题解 | #牛牛的书#

牛牛的书

https://www.nowcoder.com/practice/30bb969e117b4f6d934d4b60a2af7489

#include<stdio.h> 

struct book{
	char bookname[100];
	int price;
};


int main(){
	int n;
	scanf("%d",&n);
	struct book num[n]; 
	for(int i=0;i<n;i++){//	in 
		scanf("%s %d",num[i].bookname,&num[i].price); 
	}
	
	for(int i=0;i<n-1;i++){	//排序 
		for(int j=0;j<n-i-1;j++){
			if(num[j].price>num[j+1].price){ //swap
				struct book stemp;
					stemp=num[j];
					num[j]=num[j+1];
					num[j+1]=stemp;
			}
		} 
	}
	
	for(int i=0;i<n;i++){	//	print
		printf("%s\n",num[i].bookname);	
	}
	
	return 0;
}

全部评论

相关推荐

最喜欢秋天的火龙果很...:第一份工作一定要往大的去,工资低点没事。后面换工作会更好找,即使你去小公司,你也不可能不会换工作的。所以找大的去
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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