题解 | #小白鼠排队#

小白鼠排队

https://www.nowcoder.com/practice/27fbaa6c7b2e419bbf4de8ba60cf372b

#include<cstdio>
#include<algorithm>
using namespace std;
struct mouse{
	int weight;
	char colour[10];
};
bool comp(mouse lhs, mouse rhs){
	if (lhs.weight > rhs.weight){
		return true;
	}
	else{
		return false;
	}
}
int main(){
	int n;
	mouse s[100];
	while (scanf("%d", &n) != EOF){
		for (int i = 0; i < n; i++){
			scanf("%d %s", &s[i].weight, &s[i].colour);
		}
		sort(s, s + n, comp);
		for (int i = 0; i < n; i++){
			printf("%s\n", s[i].colour);
		}
	}
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务