题解 | #牛牛的书#
牛牛的书
https://www.nowcoder.com/practice/30bb969e117b4f6d934d4b60a2af7489
#define _CRT_SECURE_NO_WARNINGS 1 #include <stdio.h> #include<stdlib.h> struct book { char name[100]; int price; }; int cmp_price(const void* e1, const void* e2) { return (*(struct book*)e1).price - (*(struct book*)e2).price; } int main() { int n = 0; scanf("%d", &n); struct book b1[100]; for (int i = 0; i < n; i++) { scanf("%s %d", b1[i].name, &(b1[i].price)); } int sz = sizeof(b1) / sizeof(b1[0]); qsort(b1, n, sizeof(b1[0]), cmp_price); for (int i = 0; i < n; i++) { printf("%s\n", b1[i].name); } return 0; }