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

#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;
}

全部评论

相关推荐

挣K存W养DOG:他的价值在于把他家里积攒的财富回馈给社会
点赞 评论 收藏
分享
永不遗忘:才这么点算什么拉黑,我初筛连着挂几十次了,最后还是能进面
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务