hdu-汉字统计

来源:互联网 发布:淘宝上哪个符点是真的 编辑:程序博客网 时间:2024/05/27 06:15

http://acm.hdu.edu.cn/showproblem.php?pid=2030



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

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

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

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

 

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

Sample Output
149

分析:

#include <iostream>#include <cstring>#include <cstdio>using namespace std;int main(){    int n,len;    cin>>n;    getchar();    while(n--)    {        char a[200];        gets(a);        len=strlen(a);        int s,m;        s=0;        for(int i=0;i<len;i++)        {            if(a[i]<0)            {                s++;            }        }        m=s/2;        cout<<m<<endl;    }    return 0;}