题解 | #字符统计#
字符统计
https://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
#include <functional> #include <iostream> #include <string> #include<map> #include<bits/stdc++.h> #include <vector> using namespace std; int main(){ string s; while(cin >> s){ vector<int> hash(123, 0); //统计字母和数字出现的次数 int count = 0; //记录最高次数 for(int i = 0; i < s.length(); i++){ hash[s[i]]++; count = max(count, hash[s[i]]); } while(count){ //遍历所有的次数 for(int i = 0; i < 123; i++) //从ASCⅡ码低到高找符合的输出 if(hash[i] == count) cout << char(i); count--; } cout << endl; } return 0; } // 64 位输出请用 printf("%lld")