题解 | #字符统计#
字符统计
https://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
#include <iostream> #include <map> #include <string> using namespace std; int main() { string str; cin >> str; map<char, int> mp; for (int i = str.size() - 1; i >= 0; i--) { //统计出现次数 mp[str[i]]++; } string res; for (int i = str.size(); i >= 0; i--) { //按照大小排序 for (auto x : mp) { //按照ASCII码的大小遍历一遍mp if (x.second == i) { //如果有字符次数为i的则把该字符添加到res中 res += x.first; } } } cout << res << endl; } // 64 位输出请用 printf("%lld")