题解 | #牛牛的书#
牛牛的书
https://www.nowcoder.com/practice/30bb969e117b4f6d934d4b60a2af7489
c排序你可以相信qsort,十分好用
#include<stdio.h> #include<stdlib.h> typedef struct book { char str[30]; int price; }Book; int cmd(const void*a,const void*b) { Book *c=NULL,*d=NULL; c=(Book*)a; d=(Book*)b; return c->price-d->price; } int main() { int n,i; scanf("%d",&n); Book *B=(Book*)malloc(sizeof(Book)*n); for(i=0;i<n;i++) { scanf("%s %d",B[i].str,&B[i].price); } qsort(B,n,sizeof(Book),cmd); for(i=0;i<n;i++) { printf("%s\n",B[i].str); } }