C题解

#include<stdio.h>
#include <string.h>
#include <stdlib.h>

int timesOfCharInString(char *s, char c) {
    int i = -1;
    int times = 0;
    while(s[++i] != '\0') {
        if(s[i] == c) {
            times++;
        }
    }
    return times;
}

typedef struct {
    char c;
    int times;
}CharInfo;

int main() {
    char s[20];
    while(scanf("%s", s) != EOF) {
        CharInfo infos[20];
        int len = (int)strlen(s);
        for(int i = 0; i < len; i++) {
            int t = timesOfCharInString(s, s[i]);
            CharInfo info;
            info.c = s[i];
            info.times = t;
            infos[i] = info;
        }
        int min = len;
        for(int i = 0 ; i < len; i++) {
            if(infos[i].times < min) {
                min = infos[i].times;
            }
        }
        char *result = (char *)malloc(sizeof(char) * len);
        int index = 0;
        for(int i = 0; i < len; i++) {
            CharInfo info = infos[i];
            if(info.times > min) {
                result[index++] = info.c;
            }
        }
        printf("%s\n", result);
        free(result);
        result = NULL;
    }
    return 0;
}