题解 | #字符统计#

字符统计

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

int main(void) {
    char s[1000] = "";

    while(gets(s)) {
        int result[131] = {0};
        char s1[1000] = "";
        int maxIndex = 0;
        int max = 0;
        int i = 0;
        int count = 0;
        int j =0 ;
        for(i = 0; i < strlen(s); i++) {
            result[s[i]]++;
        }
        for(i = 0; i < 131; i++) {
            if(result[i] > 0) 
                count++;
        }
        while(j < count) {
            max = 0;
            maxIndex = 0;
            for(i = 0; i < 131; i++) {
                if(max < result[i]) {
                    max = result[i];
                    maxIndex = i;
                }
            }
            result[maxIndex] = 0;
            s1[j] = (char)maxIndex;
            j++;
        }
        printf("%s\n", s1);
    }
}
全部评论

相关推荐

04-15 14:28
已编辑
Java
程序员小白条:学院+两段经典项目+技术栈,最大众的简历,纯看运气
点赞 评论 收藏
分享
评论
5
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务