题解 | 字符统计
字符统计
https://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main() {
string s;
cin >> s;
map<char, int> m;
for(const char& c: s) {
++m[c];
}
vector<pair<char, int>> vec(m.begin(), m.end());
sort(vec.begin(), vec.end(), [](auto& a, auto& b) {
if(a.second > b.second) return true;
else if(a.second == b.second) return a.first < b.first; //数量相等时按字典序从小到大排序
else return false;
});
for(auto& it: vec) {
cout << it.first;
}
return 0;
}
