题解 | 删除字符串中出现次数最少的字符
#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; }