题解 | #字符统计#

字符统计

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

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

int main() {
    string str;
    cin >> str;
    
    map<char, int> mp;
    for (int i = str.size() - 1; i >= 0; i--) { //统计出现次数
        mp[str[i]]++;
    }
    string res;
    for (int i = str.size(); i >= 0; i--) { //按照大小排序
        for (auto x : mp) { //按照ASCII码的大小遍历一遍mp
            if (x.second ==
                    i) { //如果有字符次数为i的则把该字符添加到res中
                res += x.first;
            }
        }
    }

    cout << res << endl;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

12-24 14:26
东北大学 Java
一只乌鸦:重邮+东北,好经典的学校
最后再改一次简历
点赞 评论 收藏
分享
牛马人的牛马人生:500一天吗?香麻了
投递字节跳动等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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