题解 | #小白鼠排队#

小白鼠排队

https://www.nowcoder.com/practice/27fbaa6c7b2e419bbf4de8ba60cf372b

#include <stdio.h>
#include <stdlib.h>
typedef struct{
    int weight;
    char head[11];
} mouse;
int cmp(const void *a,const void *b){
    mouse*a1=(mouse*)a;
    mouse*b1=(mouse*)b;

   return b1->weight-a1->weight;
}
int main() {
    
    int n;
    while (scanf("%d", &n) != EOF) { // 注意 while 处理多个 case
        mouse mouse1[n];
        for(int i=0;i<n;i++){
            scanf("%d %s",&mouse1[i].weight,mouse1[i].head);
        }

        qsort(mouse1,n,sizeof(mouse), cmp);
        for (int i=0; i<n; i++) {
            printf("%s\n",mouse1[i].head);
        }
    }
    return 0;
}

全部评论

相关推荐

阿武同学:基本信息保留前面三行,其他的可以全部删掉,邮箱最重要的你没写,主修课程精简到8个以内,实习里面2/3/4都是水内容的,非要写的话建议两到三句话,项目经历排版优化下,自我评价缩到三行
点赞 评论 收藏
分享
09-19 13:59
门头沟学院 Java
用微笑面对困难:Trae一下,如果真成了,他用了直接发字节起诉代码版权,,这个代码不商用是没问题的如果没成也是情理之中的。
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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