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;
}
今天做了以前没有做过的这道题目,其实很简单就是汉字的机内码是由两个负的值组成,所以我们只要遍历过去,看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;
}
相关文章推荐
- hdu 2030 汉字统计 (水)
- HDU - 2030 汉字统计 (water)
- hdu-2030-汉字统计
- hdu 2030 汉字统计
- hdu2030 汉字统计
- Hdu 2030 汉字统计
- HDU 2030 汉字统计
- HDU 2030 汉字统计
- HDU 2030 汉字统计
- HDU_2030 汉字统计
- hdu 2030 汉字统计
- HDU_2030——统计文本中汉字的个数
- HDU - 2030 汉字统计
- hdu 2030 统计汉字个数
- HDU 2030 汉字统计
- hdu2030—— 汉字统计
- hdu 2030 汉字统计
- HDU 2030 - 汉字统计
- hdu 2030 汉字统计 (java)
- HDU 2030汉字统计