题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string a;
getline(cin, a);
int lenth=a.length();
vector<int>count(26,0);
for (int i=0; i<lenth; i++) {
count[a[i]-'a']++;
}
int min=count[a[0]-'a'];
for(int i = 0; i < 26; i++)
if(min > count[i] && count[i] > 0) //一定要找到最小但不是0的次数
min = count[i];
for(int i = 0; i < lenth; i++) //输出所有出现次数大于min的字符
if(count[a[i]-'a' ] > min)
cout << a[i];
}

查看9道真题和解析