题解 | #字符统计#

字符统计

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

#include<stdio.h>

typedef struct
{
    char zifu;
    int cnt;
}node;

int main(void)
{
    char str[1001]={0};
    scanf("%s",&str);
    int len=strlen(str);
    node a[128];
    for(int i=0;i<128;i++)
    {
        a[i].zifu=i;
        a[i].cnt=0;
    }
    for(int i=0;i<len;i++)
    {
        a[str[i]].cnt++;
    }
    for(int i=0;i<128-1;i++)
    {
        for(int j=0;j<128-1-i;j++)
        {
            if(a[j+1].cnt>a[j].cnt)
            {
               node temp=a[j+1];
                a[j+1]=a[j];
                a[j]=temp;
            }
        }
    }
    for(int i=0;i<128;i++)
    {
        if(a[i].cnt!=0)
        {
            printf("%c",a[i].zifu);
        }
    }
    return 0;
}
全部评论

相关推荐

小浪_Coding:找硬件测试,也可兼顾软测欧, 简历还可以的 ,注意排版,项目写的有条理一点, 然后个人技能多加点, 润色好简历之后就开始沟通海投了,深圳,东莞这边做硬件相关的公司还不少, 医疗类,仪器类的都可以尝试
点赞 评论 收藏
分享
07-08 13:48
门头沟学院 C++
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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