题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
http://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
#include<bits/stdc++.h> using namespace std; int main() { string text; while(cin>>text){ cin.get(); int min=0; map<char, int> m; map<char, int>::iterator it; vector<int> vec; for(int i=0;i<text.length();i++) { it = m.find(text[i]); if(it != m.end()) { it->second++; } else { m[text[i]] = 1; } } for(it=m.begin();it != m.end();it++) { vec.push_back(it->second); } min = *min_element(vec.begin(), vec.end()); for(it=m.begin();it != m.end();it++) { if(it->second == min) { //删除text字符串中指定的字符 text.erase(remove(text.begin(), text.end(), it->first), text.end()); } } cout<<text<<endl; } return 0; }