题解 | #字母统计#(map解法)
字母统计
https://www.nowcoder.com/practice/de7bf0945c1c4bd1aa9d49573b831f3c
#include <iostream>
#include <map>
using namespace std;
int main() {
string str;
while(cin >> str) {
map<char, int> cnt;
for(int i = 0;i < 26; i++) {
cnt[char(int('A' + i))] = 0;
}
for(int i = 0;i < str.length(); i++) {
if(str[i] >= 'A' && str[i] <= 'Z'){
cnt[str[i]]++;
}
}
for(auto iter = cnt.begin(); iter != cnt.end(); iter++){
cout << iter->first << ':' << iter->second << endl;
}
}
return 0;
}
查看15道真题和解析