HDU_2030——统计文本中汉字的个数

Problem Description
统计给定文本文件中汉字的个数。
 

 

Input
输入文件首先包含一个整数n,表示测试实例的个数,然后是n段文本。
 

 

Output
对于每一段文本,输出其中的汉字的个数,每个测试实例的输出占一行。

[Hint:]从汉字机内码的特点考虑~

 

 

Sample Input
2 WaHaHa! WaHaHa! 今年过节不说话要说只说普通话WaHaHa! WaHaHa! 马上就要期末考试了Are you ready?
 

 

Sample Output
14 9
 1 #include <cstdio>
 2 int main()
 3 {
 4    int n,ans;
 5    char str[1000];
 6    scanf("%d",&n);
 7    getchar();
 8    while(n--)
 9       {
10          gets(str);
11          ans=0;
12          for(int i=0;str[i];i++)
13             {
14                if(str[i]<0)
15                   {
16                      ans++;
17                   } 
18             }
19          printf("%d\n",ans/2);
20       }
21    return 0;     
22 }

 

posted @ 2013-06-18 18:05  瓶哥  Views(432)  Comments(0Edit  收藏  举报