hdu 2030 汉字的编码方式

要点:一个汉字占两个字节,且这两个字节对应的整数值为负,即符号位是1

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 using namespace std;
 5 
 6 const int N = 10001;
 7 char str[N];
 8 
 9 int main ()
10 {
11     int t;
12     cin >> t;
13     getchar();
14     while ( t-- )
15     {
16         cin.getline( str, N - 1 );
17         int len = strlen(str), cnt = 0;
18         for ( int i = 0; i < len; i++ )
19         {
20             if ( str[i] < 0 ) cnt++;
21         }
22         cout << cnt / 2 << endl;
23     }
24     return 0;
25 }

 

posted @ 2015-05-03 18:41  hxy_has_been_used  阅读(244)  评论(0编辑  收藏  举报