题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
http://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
#include <iostream>
using namespace std;
int main() {
string str;
char output[21];
while(cin >> str) {
int i, j, chars[26] = {0}, min=20;
for(i = 0; i < str.size(); i++) { // 统计出现的次数
chars[str[i] - 'a']++;
}
for (i = 0; i < 26; i++) { // 确定最小出现的次数
if (chars[i] != 0 && chars[i] < min)
min = chars[i];
}
for (j = 0, i = 0; i < str.size(); i++) {
if (chars[str[i] - 'a'] != min) { // 将符合条件的字符放入OUTPUT
output[j++] = str[i];
}
}
output[j] = '\0';
cout << output << endl;
}
}