90分,向大佬们求助
查看原帖
90分,向大佬们求助
1265947
honey8848楼主2024/1/28 19:47
#include<iostream>
#include<string>
#include<stdio.h>
#include<algorithm>
using namespace std;
struct student
{
	int score;
	int x;
	int y;
	int z;
	int number;
};
bool cmp(const student& a, const student& b)
{
	if (a.score == b.score)
	{
		if (a.x == b.x)
		{
			if (a.y == b.y)
			{
				if (a.z == b.z)
				{
					return a.number < b.number;
				}
				else
				{
					return a.z > b.z;
				}
			}
			else
			{
				return a.y > b.y;
			}
		}
		else
		{
			return a.x > b.x;
		}
	}
	else
	{
		return a.score > b.score;
	}
}
int main()
{
	struct student stu[300];
	int n;
	cin >> n;
	int i;
	for (i = 0; i < n; i++)
	{
		cin >> stu[i].x >> stu[i].y >> stu[i].z;
		stu[i].score = stu[i].x + stu[i].y + stu[i].z;
		stu[i].number = i + 1;
	}
	sort(stu, stu + n, cmp);
	if (n > 5)
	{
		n = 5;
	}
	for (i = 0; i < n; i++)
	{
		cout << stu[i].number << ' ' << 				stu[i].score << endl;
	}
	return 0;
}
2024/1/28 19:47
加载中...