题解 | #字符统计#
字符统计
https://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
#include <iostream> #include <string> #include <vector> #include <map> #include <algorithm> using namespace std; int main() { string strs; cin >> strs; map<char, int> data; for (int i = 0;i < strs.size();i++) { data[strs[i]] += 1; } vector<pair<char,int>> temp(data.begin(),data.end()); sort(temp.begin(),temp.end(),[](const pair<char,int> a,const pair<char,int> b) { if (a.second != b.second) { return a.second > b.second; } else { return a.first < b.first; } }); for (auto it : temp) { cout << it.first; } } // 64 位输出请用 printf("%lld")