汉字统计

时间:2014-10-28 13:37:01   收藏:0   阅读:286
Problem Description
统计给定文本文件中汉字的个数。
 
Input
输入文件首先包含一个整数n,表示测试实例的个数,然后是n段文本。
 
Output
对于每一段文本,输出其中的汉字的个数,每个测试实例的输出占一行。

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

 
Sample Input
2 WaHaHa! WaHaHa! 今年过节不说话要说只说普通话WaHaHa! WaHaHa!
马上就要期末考试了Are you ready?
 
Sample Output
14
9
 
 1 #include <stdio.h>
 2 
 3 int main(){
 4     int T;
 5     char c;
 6     int amount;
 7     
 8     scanf("%d",&T);
 9     getchar();
10     
11     while(T--){
12         amount=0;
13         while((c=getchar())!=\n){
14             if(c<0 || c>127)
15                 amount++;
16         }
17         printf("%d\n",amount/2);
18     }
19         
20     
21     return 0;
22 }

 

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!