2030 汉字统计

Problem Description

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




Input

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




Output

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

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






Sample Input

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





Sample Output

14
9

code:

 1 #include<iostream>
 2 using namespace std;
 3 
 4 int main(){
 5     int n,i,j,k;
 6     int l;
 7     string s;
 8     cin >> n;
 9     getchar();
10     while(n--)
11     {
12         k=0;
13         getline(cin, s);
14         l=s.length();
15         for(i=0;i<l;i++)
16         {
17             if(s[i]<32)
18                 k++;
19         }
20         cout << k/2 <<endl;
21     }
22     return 0;
23 }
原文地址:https://www.cnblogs.com/gaosshun/p/3502780.html