题解 | #字符统计#

字符统计

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

#include<stdio.h>
struct node
{
    int alpha;
    int count;
};
int main()
{
    char str[1001];
    while(scanf("%s",str)!=EOF)
    {
        int len=strlen(str);
        struct node s[128];
        for(int i=0;i<128;i++)//让s与ASCII相关
        {
            s[i].alpha=i;
            s[i].count=0;
        }
        /*for(int i=0;i<128;i++)
        {
            printf("%d",s[i].alpha);
        }*/
        for(int i=0;i<len;i++)
        {
            s[(int)str[i]].count++;
        }
        /*for(int i=0;i<128;i++)
        {
            printf("%d",s[i].count);
        }
        printf("\n");*/
        for(int i=0;i<128;i++)
        {
            for(int j=0;j<128-i-1;j++)
            {
                if(s[j].count<s[j+1].count)
                {
                    struct node temp=s[j];
                    s[j]=s[j+1];
                    s[j+1]=temp;
                }
            }
        }
        for(int i=0;i<128;i++)
        {
            if(s[i].count!=0)
            {
                printf("%c",s[i].alpha);
            }
        }
        printf("\n");
    }
    return 0;
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-11 12:10
点赞 评论 收藏
分享
07-09 18:33
门头沟学院 Java
这么逆天每年都有人去???&nbsp;填多益网申就是大型的服从性测试
鲁大牛:辅导员在群里发了这个公司我就申了一下。网申居然要写当场开摄像头写两篇不少于三百字的作文。太逆天了
点赞 评论 收藏
分享
评论
3
1
分享

创作者周榜

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