题解 | #统计字符#
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[]){
string str;
getline(cin, str);
int alpha = 0;
int space = 0;
int digit = 0;
int other = 0;
for(char c : str){
if(c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'){
++alpha;
}
else if(c == ' '){
++space;
}
else if(c >= '0' && c <= '9'){
++digit;
}
else{
++other;
}
}
cout << alpha << endl;
cout << space << endl;
cout << digit << endl;
cout << other << endl;
return 0;
}