题解 | #字符统计#

字符统计

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

全部评论

相关推荐

01-16 18:34
四川大学 Java
欢迎加入AI:没有啥稳定不稳定,一切都源于业务快速发展还是收缩。我当年一开始去的央企,业务不赚钱,也贼卷,慢慢就开始优化了。。。
点赞 评论 收藏
分享
人生一梦:24年我投暑期实习,它以我不是女的为理由拒绝了我查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务