题解 | #HJ102字符统计#

字符统计

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

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

int main() {
    char str[1000]={0};
    int a[255]={0};
    scanf("%[^\n]\n",str);
    for(int i=0;i<strlen(str);i++)
    {
        a[str[i]]++;
    }
    int maxcount=a[0];
    for(int i=0;i<255;i++)
    {
        if(a[i]>maxcount)
        {
            maxcount = a[i];
        }
    }
    while(maxcount)
    {
    for(int i=0;i<255;i++)
    {
        if(a[i]==maxcount){
            printf("%c",(char)(i));
        }  
    }
    maxcount--;
    }
   // printf("%d",maxcount);
    
    return 0;
}

全部评论

相关推荐

09-23 15:37
门头沟学院 Java
面了100年面试不知...:ai面:请你说一下在无的论文/项目中,你具体做了什么
我的秋招日记
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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