题解 | #字符统计#
字符统计
https://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0
// HJ102-2 字符统计.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
map<char, int>mm;
while (cin >> s)
{
mm.clear();
for (int i = 0; i < s.size(); i++)
{
mm[s[i]]++;
}
vector<pair<char, int>>dp(mm.begin(),mm.end());
stable_sort(dp.begin(), dp.end(), [](const pair<char, int>& a, const pair<char, int>& b)
{
return a.second > b.second;
});
for (auto it=dp.begin();it!=dp.end();it++)
{
cout << it->first;
}
cout << endl;
}
return 0;
}