这一题只要想通思路就不难了,
花了我挺长时间,只是一直都没想到一个很好的方法,
因为一个汉字是由两个字符组成的,且都是负的
所以,这要求出所有负的字符个数,再除以2就是汉字个数了,
以下是代码::
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
int main ()
{
int n, i;
char str[1050];
int count, len;
cin >> n;
gets(str);
while (n--)
{
count = 0;
gets (str);
len = strlen(str);
for (i = 0; i < len; i ++)
if (str[i] < 0)
count ++;
printf ("%d\n", count/2);
}
system ("pause");
return 0;
}