题解 | #牛牛的书#

牛牛的书

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

全部评论

相关推荐

04-18 15:58
已编辑
门头沟学院 设计
kaoyu:这一看就不是计算机的,怎么还有个排斥洗碗?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务