题解 | #删除字符串中出现次数最少的字符#

删除字符串中出现次数最少的字符

https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9

#include <cctype>
#include <iostream>
#include <limits>
#include <sstream>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;

int main() {
    unordered_map<char, int> hash_map;
    for (auto c='a'; c<='z'; c++) {
        hash_map[c]= 0;
    }
    string s;
    cin>>s;
    for(auto c:s){
        hash_map[c] +=1;
    }
    int min = numeric_limits<int>::max();
    for(auto c:s){
        if(hash_map[c] < min){
            min = hash_map[c];
        }
    }
    for (auto c:s) {
        if(hash_map[c] == min){
            hash_map[c]=0;
        }
    }
    for (auto c:s) {
        if (hash_map[c]!=0) {
        
            cout<< c;
        
        }
        
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

01-08 12:01
门头沟学院 Java
冰炸橙汁_不做oj版:不接好运
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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