题目链接:统计字符_牛客题霸_牛客网
注意点:
统计英文字母注意大小写的都要统计
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s;
getline(cin,s);
int cnt_word = 0,cnt_blank = 0, cnt_number = 0, cnt_other = 0;
for (int i = 0; i < s.size(); ++i){
//英文单词
if ((s[i] >= 'a' && s[i] <='z') || (s[i] >='A' && s[i] <='Z')) ++cnt_word;
//空格
else if(s[i] == ' ') ++cnt_blank;
//数字
else if(s[i] >= '0' && s[i] <='9') ++cnt_number;
//其他字符
else ++cnt_other;
}
cout << cnt_word << endl;
cout << cnt_blank <<endl;
cout << cnt_number <<endl;
cout << cnt_other <<endl;
return 0;
}