HDU2030 汉字统计

【题目】


【思路】汉字机内码使用二个字节,汉字的每个字节都是<0的,即其每个字节最高位一位为1。

【代码】AC的C++代码如下:

#include <iostream>
#include <string.h>
using namespace std;
int main()
{
    int n;
    char s[1024];
    cin >> n;
    int count;
    getchar();
    while (n--)
    {
        count = 0;
        gets(s);
        int len = strlen(s);
        for (int i = 0;i < len;i++)
        {
            if (s[i] == '\n')
                break;
            if (s[i] < 0)
                count++;
        }
        cout << count / 2 << endl;
    }
    return 0;
}


猜你喜欢

转载自blog.csdn.net/m0_38056893/article/details/80086001