题解 | #字符统计#
字符统计
https://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
##利用map,set树的自动排序,效率略有提高 #include <iostream> #include <map> #include <set> using namespace std; int main() { char a; map<char,int > st; map<int,set<char> > st2; while (cin >> a ) { ++st[a]; } for(auto ite = st.begin();ite != st.end();++ite){ st2[ite->second].insert(ite->first); } for(auto ite = st2.rbegin();ite != st2.rend();++ite){ for(auto ite2= ite->second.begin(); ite2 != ite->second.end(); ++ite2){ cout<<*ite2; } } }