自己写的。C语言。题解 | #字符统计#

字符统计

https://www.nowcoder.com/practice/c1f9561de1e240099bdb904765da9ad0

#include<stdio.h>
int main() {
    int c;
    int count[128] = {0};
    int i = 0, max;
    while ((c = getchar()) != 10) {
        count[c]++;
    }
    while (1) {
        max = 0;
        for (i = 0; i < 128; i++) {
            if (count[i] > max) {
                max = count[i];
            }
        }
        if (max == 0) {
            break;
        }
        for (i = 0; i < 128; i++) {
            if (count[i] == max) {
                printf("%c", i);
                count[i] = 0;
                i = 128;
            }
        }
    }
    printf("\n");
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务