题解 | #统计字符#
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
#include <iostream>
using namespace std;
int main() {
int en = 0;
int spa = 0;
int num = 0;
int other = 0;
string str;
getline(cin,str);
cin>>str;
for(int i = 0;i<str.size();i++){
if(str[i]>='a'&&str[i]<='z'){
en++;
}else if(str[i]>='A'&&str[i]<='Z'){
en++;
}else if(str[i]>='0'&&str[i]<='9'){
num++;
}else if(str[i] == ' '){
spa++;
}else{
other++;
}
}
cout<<en<<endl;
cout<<spa<<endl;
cout<<num<<endl;
cout<<other<<endl;
}
// 64 位输出请用 printf("%lld")
