代码
#include <iostream>
using namespace std;
int main() {
int n;
cin>>n;
string s;
getline(cin, s);
for(int i=0; i<n; i++){
string str;
getline(cin, str);
int count = 0;
for(int j=0; j<str.length(); j++){
if(str.at(j)<0){
count++;
}
}
int ans = count/2;
cout<<ans<<endl;
}
return 0;
}
注解
1、汉字:汉字机内码使用二个字节,汉字的每个字节都是<0的,即其每个字节最高位一位为1。C/C++语言补码第一位是符号位,1表示为负数。