您的位置:首页 > 其它

hdu 2030 汉字统计

2011-08-02 22:31 267 查看
http://acm.hdu.edu.cn/showproblem.php?pid=2030

今天做了以前没有做过的这道题目,其实很简单就是汉字的机内码是由两个负的值组成,所以我们只要遍历过去,看a[i]负数的个数,再除以2即得到了该字符串内汉字的个数。。。

代码如下:

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

int main()

{

int n;

char a[1002];

scanf("%d%*c",&n);

while(n--)

{

gets(a);

int k=strlen(a),c=0;

for(int i=0;i<k;++i)

{

if(a[i]<0) c++;

}

printf("%d\n",c/2);

}

// system("pause");

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: