题解 | #字母统计#开个大小为26的数组计数就行
字母统计
https://www.nowcoder.com/practice/de7bf0945c1c4bd1aa9d49573b831f3c
#include <iostream> using namespace std; int main() { int counts[26]{}; string s; cin >> s; for (char c: s) { if (c >= 'A' && c <= 'Z') counts[c - 'A']++; } for (int i = 0; i < 26; i++) { cout << (char) (i + 'A') << ':' << counts[i] << endl; } return 0; }