hdu 2030 汉字统计

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;

}

原文地址:https://www.cnblogs.com/yuelingzhi/p/2125570.html