关键要知道汉字是占两个字符的,且每个字符的值都<0;直接用字符就可以做的。但要记得输入字符前加个getchar();

代码:

#include"iostream"
#include"string"
using namespace std;
int main()
{
 int n;
 char c;
 cin>>n;
 getchar();
 while(n--)
 {
  int s=0;
  while((c=getchar())!='\n')
  { 
    if(c<0)
     s++;
  }
  cout<<s/2<<endl;
 
 }
 return 0;
}

posted on 2012-07-07 10:07  xinmenghuairi  阅读(202)  评论(0编辑  收藏  举报