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

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

int main() {
    string str;
    cin >> str;
    map<char, int> mmc;
    for (char c: str) {
        if (islower(c))
        {
            ++mmc[c];
        }
        else {
            return -1;
        }
    }
    
    int minCount = mmc.size();
    for (auto & it : mmc)
    {
        if (it.second < minCount)
        {
            minCount = it.second;
        }
    }

    for (char c : str) {
        if (mmc[c] > minCount)
        {
            cout << c;
        }
    }

    cout << endl;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-08 13:15
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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