题解 | 小白鼠排队

小白鼠排队

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

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
    int weight;
    char color[11]; 
} Rat;
int compare(const void* a, const void* b) {
    Rat* rat1 = (Rat*)a;
    Rat* rat2 = (Rat*)b;
    return rat2->weight - rat1->weight; 
}
int main() {
    int N;
    while (scanf("%d", &N) != EOF) { 
        Rat rats[100]; 
        for (int i = 0; i < N; i++) {
            scanf("%d %s", &rats[i].weight, rats[i].color); 
        }
        qsort(rats, N, sizeof(Rat), compare);
        for (int i = 0; i < N; i++) {
            printf("%s\n", rats[i].color);
        }
    }
    return 0;
}

qsort+数据结构 easy

全部评论

相关推荐

nus2201602...:兄弟,你这个简历撕了丢了吧,就是一坨,去找几个项目,理解项目流程,看几遍就是你的了,看看八股就去干了,多看看牛客里别人发出来的简历,对着写,你这写的啥啊,纯一坨
点赞 评论 收藏
分享
每晚夜里独自颤抖:你cet6就cet6,cet4就cet4,你写个cet证书等是什么意思。专业技能快赶上项目行数,你做的这2个项目哪里能提现你有这么多技能呢
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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