题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
http://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
#include <iostream> #include <string> #include <vector> using namespace std; int main() { string s; while(cin >> s) { vector<int> cnt(26, 100); for(auto ch : s) { if(cnt[ch - 'a'] == 100) { cnt[ch - 'a'] = 1; } else { cnt[ch - 'a'] += 1; } } int min_num = 100; for(auto item : cnt) { min_num = min(min_num, item); } string res = ""; for(auto ch : s) { if(cnt[ch - 'a'] != min_num) res += ch; } cout << res << endl; } return 0; }