汉字统计



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

 

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

 

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

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

 

 

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

 

Sample Output
14
9
     长知识了,我只知道汉字占两字节,想靠汉字的字节数来判断,行不通,原来 汉字的ASCLL码是负的啊(一个汉字占两字节,所以会出现两次负号)。
        
 1 #include<iostream>
 2 #include<iomanip>
 3 //#include<bits/stdc++.h>
 4 #include<cstdio>
 5 #include<cmath>
 6 #include<cstring>
 7 #include<sstream>
 8 #include<algorithm>
 9 #define PI  3.14159265358979
10 #define LL long long
11 #define  eps   0.00000001
12 #define LL long long
13 using namespace std;
14 int main()
15 {
16     char c[1000];
17     int T;
18     cin>>T;
19     getchar();
20     while(T--)
21     {
22         gets(c);
23         int sum=0;
24         int L=strlen(c);
25         for(int i=0;i<L;++i)
26         {
27             if(int(c[i])<0) ++sum;
28 
29         }
30         cout<<sum/2<<endl;
31     }
32 }
View Code

 

posted @ 2019-05-01 21:14  Auroras  阅读(362)  评论(0编辑  收藏  举报