题解 | #字母统计#
字母统计
https://www.nowcoder.com/practice/de7bf0945c1c4bd1aa9d49573b831f3c
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
string str;
map<char, int> tempMap = {{'A',0},{'B',0},{'C',0},{'D',0},
{'E',0},{'F',0},{'G',0},{'H',0},
{'I',0},{'J',0},{'K',0},{'L',0},
{'M',0},{'N',0},{'O',0},{'P',0},
{'Q',0},{'R',0},{'S',0},{'T',0},
{'U',0},{'V',0},{'W',0},{'X',0},{'Y',0},{'Z',0}};
while (getline(cin, str)) {
for (char & i : str) {
if ('A' <= i && i <= 'Z') {
tempMap[i]++;
}
}
for (auto & iter : tempMap) {
printf("%c:%d\n",iter.first,iter.second);
iter.second = 0;
}
}
return 0;
}
