HDU2030 汉字统计

解题思路:一个汉字在字符串中是以两个负的字符形式存储的。

    所以只要统计字符串中负的字符的个数并除以二就可以了。

 1 #include<cstdio>
 2 #include<cstring>
 3 using namespace std;
 4 const int maxn = 240000;
 5 char str[maxn];
 6 int main()
 7 {
 8     int n;
 9     scanf("%d", &n);
10     getchar();
11     while(n--)
12     {
13         gets(str);
14         int len = strlen(str);
15         int cnt = 0;
16         for(int i = 0; i < len; i++)
17         if(str[i] < 0) cnt ++;
18         printf("%d\n", cnt / 2);
19     }
20     return 0;
21 }
View Code

 

posted on 2015-10-29 15:20  改写历史,倾尽天下  阅读(181)  评论(0编辑  收藏  举报

导航