题解 | #统计字符#
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
#include <iostream> #include <string> #include <vector> using namespace std; int main() { string s; while (getline(cin, s)) { // 注意 while 处理多个 case vector<int> ans(4, 0); for (char c : s) { if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) { ans[0]++; } else if (c == ' ') { ans[1]++; } else if (c >= '0' && c <= '9') { ans[2]++; } else { ans[3]++; } } for(auto i : ans) { cout << i << endl; } } } // 64 位输出请用 printf("%lld")