题解 | #统计字符#
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
#include <bits/stdc++.h> #include <iostream> using namespace std; int main() { string text; while (getline(cin, text)) { // 注意 while 处理多个 case int a = 0, b = 0, c = 0, d = 0; for (const char ch : text) { if (isalpha(ch)) { a++; } else if (1 == isblank(ch)) { b++; } else if (1 == isdigit(ch)) { c++; } else { d++; } } cout << a << endl << b << endl << c << endl << d << endl; } }