文章
27
粉丝
86
获赞
10
访问
30.4k
C++
注意:stable_sort,否则直接WA,通过率0%
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct b{
char ch;
int cnt;
};
bool cmp(b num1, b num2){
if(num1.cnt == num2.cnt){
num1.ch - '0' < num2.ch - '0';
}
return num1.cnt > num2.cnt;
}
int main(){
string str;
while(getline(cin, str)){
string::iterator sit;
vector<char> a;
for(sit = str.begin(); sit != str.end(); sit++){
a.push_back(*sit);
}
sort(a.begin(), a.end());
vector<char>::iterator cit;
vector<b> chars;
int cnt = 0;
for(cit = a.begin(); cit != a.end(); cit++){
if(cit != a.end() - 1 && *cit == *(cit + 1)){
cnt++;
}
else{
b temp;
temp.ch = *cit;
temp.cnt = cnt + 1;
chars.push_back(temp);
cnt = 0;
}
}
stable_sort(chars.begin(), chars.end(), cmp);
for(int i = 0; i < chars.size(); i++){
for(int j = 0; j < cha...
登录后发布评论
暂无评论,来抢沙发