题解 | #字符统计#

字符统计

https://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main() {
    string strs;
    cin >> strs;
    map<char, int> data;
    for (int i = 0;i < strs.size();i++)
    {
        data[strs[i]] += 1;
    }
    vector<pair<char,int>> temp(data.begin(),data.end());

    sort(temp.begin(),temp.end(),[](const pair<char,int> a,const pair<char,int> b)
    {
        if (a.second != b.second)
        {
            return a.second > b.second;
        }
        else
        {
            return a.first < b.first;
        }
    });

    for (auto it : temp)
    {
        cout << it.first;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

拼搏白天我要去影石飓风&nbsp;太羡慕了&nbsp;能不能全中国的公司都推行啊
牛可乐:看了下官网只有这个能干了,我现在去考营养师资格证查看图片
投递影石Insta360等公司10个岗位
点赞 评论 收藏
分享
09-12 18:28
门头沟学院 Java
网友描述的太精准了👍
迷茫的大四🐶:不管活脏还是累,钱到位就行,钱到位啥都不用抱怨
投递字节跳动等公司10个岗位
点赞 评论 收藏
分享
点赞 评论 收藏
分享
08-28 20:36
门头沟学院 Java
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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