HDOJ  2030   汉字统计

来源:互联网 发布:百度世界人工智能大会 编辑:程序博客网 时间:2024/05/22 02:13

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

做这一道题只要知道汉字的机内码就可以了,
汉字的ASCII码的首位是1,所以为负,.
而且汉字是用两个字节编码的
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
 char a[1000];
 int i,k,p,n;
 cin>>n;
 getchar();
 while(n--)
 {
    cin.getline(a,1000);
    p=0;
       k=strlen(a);
       for(i=0;i<k;i++)
           if(a[i]<0)
               p++;
       cout<<p/2<<endl;
 }
 return 0;
}

0 0
原创粉丝点击