题解 | #小白鼠排队#

小白鼠排队

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;
}

全部评论

相关推荐

祈求顺利毕业😁:简历很好了,多投吧牛油😂。主要是环境不好,大家也卷
点赞 评论 收藏
转发
1 收藏 评论
分享
牛客网
牛客企业服务