题解 | #字符统计#

字符统计

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;
}

全部评论

相关推荐

有担当的灰太狼又在摸鱼:零帧起手查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务