HDU 2030 汉字统计(汉字Asics码为负,占两个char)

传送门:

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

汉字统计

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 56727    Accepted Submission(s): 30667


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

 

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

 

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

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

 

 

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

 

Sample Output
14 9
 

 

Author
lcy
 

 

Source
 

 

Recommend
lcy   |   We have carefully selected several similar problems for you:  2031 2032 2033 2034 2036 
 
分析:

汉字Asics码为负,占两个char

code:

#include <stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include <iostream>
#define max_v 1024
char a[max_v];
int main()
{
    int n;
    scanf("%d",&n);
    getchar();
    while(n--)
    {
        gets(a);
        int l=strlen(a);
        int sum=0;
        for(int i=0;i<l;i++)
        {
            if(a[i]<0)
                sum++;
        }
        printf("%d\n",sum/2);
    }
    return 0;
}

 

posted @ 2018-07-26 11:02  西*风  阅读(179)  评论(0编辑  收藏  举报