#include <iostream>
using namespace std;
#include <cctype>
#include <string>
int main() {
string str;
getline(cin,str);
int en = 0;
int space = 0;
int num = 0;
int others = 0;
for(char i : str){
if(isalpha(i)){
en++;
}
else if(i == ' '){
space++;
}
else if(isdigit(i)){
num++;
}
else{
others++;
}
}
cout << en << endl;
cout << space << endl;
cout << num << endl;
cout << others << endl;
}
可以用cctype库,如果不用,那用ASCII码来判断也是完全没问题的

京公网安备 11010502036488号