题解 | #统计字符#
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5?tpId=37&tqId=21263&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26pageSize%3D50%26search%3D%26tpId%3D37%26type%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main() {
string str;
int a =0,b =0,c =0,d =0;
getline(cin,str);
for(int i =0;i <str.length();i++){
if(isalpha(str[i])){
a++;
}
if(isspace(str[i])){
b++;
}
if(isdigit(str[i])){
c++;
}
if(ispunct(str[i])){
d++;
}
}
cout << a <<endl;
cout << b <<endl;
cout << c <<endl;
cout << d <<endl;
}