题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
http://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
#include <string.h>
int main(void) {
char str[21];
int index[21] = {0};
int hash[21] = {0};
scanf("%s", str);
int length = (int) strlen(str);
for (int i = 0; i < length; ++i) {
index[i] = 1;
for (int j = 0; j < length; ++j) {
if (i == j)
continue;
else {
if (str[i] == str[j])
index[i]++;
else
continue;
}
}
}
for (int i = 0; i < length; ++i) {
if (index[i] == 1)
continue;
else {
for (int j = 0; j < length; ++j) {
if (i == j)
continue;
else {
if (index[i] > index[j]) {
hash[i] = 1;
break;
}
}
}
}
}
for (int k = 0; k < length; ++k) {
if (hash[k] == 1)
printf("%c", str[k]);
else
continue;
}
return 0;
}