题解 | #统计字符#__huawei_no.40-1
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
#include <iostream> using namespace std; int main() { string str; getline(cin,str); int count_1 = 0; int count_2 = 0; int count_3 = 0; int count_4 = 0; for(char c : str){ if ( c >= '0' && c <= '9'){ count_3++; } else if(c >= 'A' && c <= 'Z'){ count_1++; } else if (c >= 'a' && c <= 'z'){ count_1++; } else if ( c == ' '){ count_2++; } else{ count_4++; } } cout << count_1<<endl; cout << count_2<<endl; cout << count_3<<endl; cout << count_4<<endl; return 0; } // 64 位输出请用 printf("%lld")
简单粗暴的解决