题解 | #字符统计#

字符统计

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

#include <functional>
#include <iostream>
#include <string>
#include<map>
#include<bits/stdc++.h>
#include <vector>
using namespace std;
int main(){
    string s;
    while(cin >> s){
        vector<int> hash(123, 0); //统计字母和数字出现的次数
        int count = 0; //记录最高次数
        for(int i = 0; i < s.length(); i++){
            hash[s[i]]++;
          count = max(count, hash[s[i]]);
        }
        while(count){ //遍历所有的次数
            for(int i = 0; i < 123; i++) //从ASCⅡ码低到高找符合的输出
                if(hash[i] == count)
                    cout << char(i);
            count--;
        }
        cout << endl;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

测试糕手手:社会第一课,随便吹牛逼,直接说四个月,别老实。老实人只会被欺负
点赞 评论 收藏
分享
07-02 13:52
门头沟学院 Java
点赞 评论 收藏
分享
zhch7:建议9✌️把学历加黑加粗,如果实在offer可能是觉得佬不会去
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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