题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
http://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
template<typename T>
bool isConstains(const vector<T>& v, T t) {
return find(v.begin(), v.e***.end();
}
int main() {
string str;
cin >> str;
vector<int> v(26,0);
for(char c : str) {
int index = c-'a';
v.at(index)++;
}
int max = 26;
for(int i : v) {
if(i!=0&&i<max) max = i;
}
vector<char> del;
for(int i = 0; i < v.size(); i++) {
if(v.at(i)==max) del.push_back('a'+i);
}
for(char c : str) {
if(!isConstains(del, c)) cout << c;
}
cout << endl;
return 0;
}