首页 > 其他 > 详细

HDU2030 汉字统计

时间:2015-10-29 16:07:03      阅读:155      评论:0      收藏:0      [点我收藏+]

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

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

技术分享
 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

 

HDU2030 汉字统计

原文:http://www.cnblogs.com/loveprincess/p/4920632.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!