题解 | #字符统计#

字符统计

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

全部评论

相关推荐

大飞的诡术妖姬:之前看b站多明海有个说法,日本就业竞争非常低的原因不光是毕业学生少,还有很多人干两年不喜欢职场氛围就辞职躺平,位置也空了很多,论吃苦耐劳还得看咱们
点赞 评论 收藏
分享
龙珠传说:nb,公务员解约不需要支付违约金吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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