Problem Description
统计给定文本文件中汉字的个数。
Input
输入文件首先包含一个整数n,表示测试实例的个数,然后是n段文本。
Output
对于每一段文本,输出其中的汉字的个数,每个测试实例的输出占一行。
[Hint:]从汉字机内码的特点考虑~
Sample Input
2
WaHaHa! WaHaHa! 今年过节不说话要说只说普通话WaHaHa! WaHaHa!
马上就要期末考试了Are you ready?
Sample Output
14
9
https://wenku.baidu.com/view/b9b5fbf6aa00b52acfc7caa9.html
#include
#include
int main()
{ char a[200];
int n,k,i,t;
scanf("%d",&n);
getchar();
while(n--)
{ t=0;
gets(a);
k=strlen(a);
for(i=0;i<k;i++)
if(a[i]<0)
t++;
printf("%d\n",t/2);
}
return 0;
}
note:
(1)汉字的ASCLL码是负的,靠这个才能判断汉字。
(2)汉字是两个字节,所以最后的次数要除以2.