题解 | #小白鼠排队#qsort+结构体
小白鼠排队
https://www.nowcoder.com/practice/27fbaa6c7b2e419bbf4de8ba60cf372b
#include <stdio.h> #include <stdlib.h> typedef struct Mouse{ int weight; char color[11]; }Mouse; Mouse mouse[101]; int cmp(Mouse*a,Mouse*b) { return b->weight-a->weight; } int main() { int a; while (scanf("%d", &a) != EOF) { // 注意 while 处理多个 case for(int i=0;i<a;i++) scanf("%d %s",&mouse[i].weight,mouse[i].color); qsort(mouse,a,sizeof(Mouse),cmp); for(int i=0;i<a;i++) printf("%s\n",mouse[i].color); } return 0; }