题解 | 字母统计
#include <iostream> #include <map> #include <string> using std::cout; using std::cin; using std::endl; using std::string; using std::map; int main() { string str; while(cin >> str){ map<char,int> Map; string tmp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; for(auto elem : tmp) Map[elem] = 0; // 初始化 for(auto elem : str){ if(elem >= 'A' && elem <= 'Z'){ Map[elem]++; } } for(auto& [k,v] : Map){ cout << k << ':' << v << endl; } } return 0; }