typedef pair<char, int> PAIR;
struct CmpByValue {
bool operator()(const PAIR& lhs, const PAIR& rhs) {
return lhs.second > rhs.second;
}
};
string frequencySort(string s) {
map<char,int> record;
for(int i=0;i<s.size();i++)
record[s[i]]++;
vector<PAIR> name_count_vec(record.begin(),record.end());
sort(name_count_vec.begin(),name_count_vec.end(),CmpByValue());
string ret="";
for(vector<PAIR>::iterator it=name_count_vec.begin();it!=name_count_vec.end();it++){
for(int i=0;i<it->second;i++){
ret=ret+it->first;
}
}
return ret;
}
老师帮我看下,哪里的问题?