HDOJ 2030 统计汉字个数

/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
typedef unsigned long long ULL;
using namespace std;

const int maxn = 100005;
char str[maxn];

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int n;
	cin >> n;
	while(n--) {
		getchar();
		cin.get(str,maxn);
		int i, cnt = 0, len = strlen(str);
		for(i = 0; i < len; i++)
			if(str[i] & 0x80)
				cnt++;
		cout << cnt / 2 << endl;
	}
	return 0;
}
/**/

汉字占两个字节。机内码为与国际码区分开来,在字符高位和下一位使用1来标识。

串中字符数字汉字,只有汉字高位为1,所以...

猜你喜欢

转载自blog.csdn.net/wen__han/article/details/82228900