文章
3
粉丝
118
获赞
0
访问
26
#include<bits/stdc++.h>
using namespace std;
typedef struct ac{
char c;
int num;
}ac;
bool cmp(ac a, ac b){
if(a.num == b.num) return a.c < b.c;
return a.num > b.num;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
while(cin >> s){
map<char, int>mp;
int ls = s.length();
ac a[ls];
for(int i = 0; i < ls; i++){
mp[s[i]]++;
}
int cnt = 0;
for(map<char, int>::iterator it = mp.begin(); it != mp.end(); it++){
char c = it->first;
int m = it->second;
a[cnt].c = c;
a[cnt].num = m;
cnt++;
}
sort(a, a + cnt, cmp);
for(int i = 0; i < cnt; i++){
for(int j = 0; j < a[i].num; j++) cout << a[i].c;
}
cout << endl;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发