题解 | 删除字符串中出现次数最少的字符
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9?tpId=37&tqId=21246&rp=1&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
// 统计每个字符出现的次数
unordered_map<char, int> freq;
for (char c : s) {
freq[c]++;
}
// 找到最小出现次数
int min_freq = INT_MAX;
for (auto& pair : freq) {
min_freq = min(min_freq, pair.second);
}
// 构建结果字符串,跳过出现次数等于最小次数的字符
string result = "";
for (char c : s) {
if (freq[c] != min_freq) {
result += c;
}
}
cout << result << endl;
return 0;
}
// 64 位输出请用 printf("%lld")

