题解 | #字符统计#
字符统计
https://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
打卡
#include <string> #include <algorithm> #include <map> using namespace std; int main() { int num[10] = { 0 }, abc[26] = { 0 }; string s; map<int, string>ans; cin >> s; for (char c : s) { if (c >= '0' && c <= '9') num[c - '0']++; else abc[c - 'a']++; } for (int i = 0; i < 10; i++) if (num[i] != 0) ans[num[i]] += '0' + i; for (int i = 0; i < 26; i++) if (abc[i] != 0) ans[abc[i]] += 'a' + i; for (auto i = ans.rbegin(); i != ans.rend(); i++) cout << i->second; }