题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
http://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
#include<bits/stdc++.h>
using namespace std;
int main(){
string str;
while(cin>>str){
//计数
int counts[26]={0};
for(int i=0;i<str.size();++i){
counts[int(str[i]-'a')]++;
}
//选最小
int min=100000;
set<char> s;
for(int i=0;i<26;++i){
if(counts[i]<=min&&counts[i]>=1)
min = counts[i];
}
for(int i=0;i<26;++i){
if(counts[i]==min)
s.insert('a'+i);
}
string res="";
for(int i=0;i<str.size();++i){
if(s.find(str[i])==s.end())
res.push_back(str[i]);
}
cout<<res<<endl;
}
return 0;
}