题解 | #成绩排序#

成绩排序

https://www.nowcoder.com/practice/0383714a1bb749499050d2e0610418b1

#include<iostream>
#include<algorithm>
using namespace std;

const int N = 1e5 + 10;

struct Stu{
	int order;
	string name;
	int score;
}stu[N];

bool cmp_0(Stu s1,Stu s2)
{
	
	return s1.score > s2.score;
}

bool cmp_1(Stu s1,Stu s2)
{

	return s1.score < s2.score;
}

int main(void)
{
	int n,type;
	while(cin >> n >> type)
	{
		for(int i = 0;i < n;i++)
		{
			cin >> stu[i].name >> stu[i].score;
		}
		if(type == 0) stable_sort(stu,stu + n,cmp_0);
		else stable_sort(stu,stu + n,cmp_1);
		for(int i = 0;i < n;i++)
		{
			printf("%s %d\n",stu[i].name.c_str(),stu[i].score);
		}	
	}
	return 0;
}




全部评论

相关推荐

轻絵梨花泪沾衣:南泵,大少爷驾到通通闪开
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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