题解 | #字母统计#EZ
字母统计
https://www.nowcoder.com/practice/de7bf0945c1c4bd1aa9d49573b831f3c
#include <iostream> #include <string> #include <cstdio> using namespace std; int main() { int count[26] = {0}; //使用0 - 25位 string str; while (getline(cin, str)) { // 注意 while 处理多个 case for (int i = 0; i < str.size(); i++) { if (str[i] >= 'A' && str[i] <= 'Z') { count[str[i] - 'A']++; } } char a = 'A'; for (int i = 0; i < 26; i++) { printf("%c:%d\n", a + i, count[i]); } } } // 64 位输出请用 printf("%lld")