题解 | #删除字符串中出现次数最少的字符#
删除字符串中出现次数最少的字符
https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9
#include <stdio.h>
typedef struct {
char c;
int num, print_enable;
}str;
int main() {
str str[20];
int i = 0, j = 0, len = 0, min;
while ((str[i].c =getchar()) != '\n') {
str[i].num = 1;
str[i].print_enable = 0; //默认全部不打印
i++;
}
len = i;
for (i = 0; i < len; i++) {
for (j = i+1; j < len; j++) {
if (str[j].num != -1) {
if (str[j].c == str[i].c) {
str[i].num++;
str[j].num = str[i].num;
}
}
}
}
for (i = 0; i < len; i++) {
for (j = 1; j < len; j++) {
if (str[i].c!=str[j].c) {
if (str[i].num > str[j].num) { //只要出现次数有比我小的就将我的打印使能打开
str[i].print_enable = 1;
}
}
}
}
for (i = 0; i < len; i++) {
if (str[i].print_enable == 1) {
printf("%c", str[i].c);
}
}
return 0;
}

