题解 | 牛牛的书

牛牛的书

https://www.nowcoder.com/practice/30bb969e117b4f6d934d4b60a2af7489

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

struct book
{
    char name[100];
    int price;

};

int main() {

    struct book num[100];
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%s%d",num[i].name,&num[i].price);
        getchar();
    }
    int m,mm;
    for(m=0;m<n-1;m++)
    {
        for(mm=0;mm<n-1-m;mm++)
        {
            if(num[mm].price>num[mm+1].price)
            {
                struct book box=num[mm];
                num[mm]=num[mm+1];
                num[mm+1]=box;
            }
        }
    }
    for(m=0;m<n;m++)
    {
        printf("%s\n",num[m].name);
    }
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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