fzu 1913 Easy Comparison(字符串)

题目链接:fzu 1913 Easy Comparison


题目大意:给出一个字符串,计算与它按照字典序排序排列后的字符串有多少个位置不同。


解题思路:水体,sort一下,然后遍历一遍就好。


 

#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

const int N = 105;

char str[N], tmp[N];

int main () {
	int cas, n;

	scanf("%d", &cas);
	for (int i = 1; i <= cas; i++) {
		scanf("%d", &n);
		scanf("%s", str);
		strcpy(tmp, str);
		sort(tmp, tmp + n);

		int ans = 0;
		for (int j = 0; j < n; j++) 
			if (str[j] != tmp[j]) ans++;
		printf("Case %d: %d\n", i, ans);

	}
	return 0;
}


 

 

posted on 2013-12-05 09:11  love so much  阅读(150)  评论(0)    收藏  举报

导航