汉字统计
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 50 Accepted Submission(s) : 33
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
统计给定文本文件中汉字的个数。
Input
输入文件首先包含一个整数n,表示测试实例的个数,然后是n段文本。
Output
对于每一段文本,输出其中的汉字的个数,每个测试实例的输出占一行。
[Hint:]从汉字机内码的特点考虑~
[Hint:]从汉字机内码的特点考虑~
Sample Input
2 WaHaHa! WaHaHa! 今年过节不说话要说只说普通话WaHaHa! WaHaHa! 马上就要期末考试了Are you ready?
Sample Output
14 9#include<stdio.h> #include<string.h> int main() { int n,l,i,count; char a[1000]; scanf("%d",&n); getchar();//消除回车 while(n--) { gets(a);//当字符串出现有空格时用gets输入,gets会把空格当成字符; count=0; l=strlen(a); for(i=0;i<l;i++) { if(a[i]<0)//汉字在ascII中为负数二个字符 count++; } printf("%d\n",count/2);//统计汉字时要把统计的负数字符除以2 } return 0; }