// #牛客春招刷题训练营# https://www.nowcoder.com/discuss/726480854079250432 #include <algorithm> #include <array> #include <iostream> using namespace std; array<pair<char, int>, 130> a;//-------------以pair为元素的数组,用来记录对应字符个数 int main() { for (int i = 0; i < 130; i++){ a[i].first = i; a[i].second = 0; } string s; cin >> s; int size = s.size(); for (int i = 0; i < size; i++){ a[s[i]].second++; } sort(a.begin(), a.end(), [&](pair<char, int> x, pair<char, int> y){return (x.second > y.second ? true : (x.second == y.second ? (x.first < y.first) : false));});//---------自定义排序,first是字符种类,以ascll记,second是字符出现次数 int i = 0; while(a[i].second){//--------只要次数不为零就一直输出 cout << a[i].first; i++; } } // 64 位输出请用 printf("%lld")