求助大佬,实在看不出哪错了
查看原帖
求助大佬,实在看不出哪错了
871843
wjklprqy楼主2022/11/10 17:15
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 310;

int n;

struct student{
	int name;
	double chinese;
	double score;
}stu[N];

bool cmp(student a, student b)
{
	if (a.score != b.score) return a.score > b.score;
	else
	{
		if (a.chinese != a.chinese) return a.chinese > b.chinese;
		else return a.name < b.name;
	}
}

int main()
{
	double a, b, c;
	cin >> n;
	
	for (int i = 1; i <= n; i ++ )
	{
		cin >> a >> b >> c;
		stu[i].name = i;
		stu[i].chinese = a;
		stu[i].score = a + b + c;
	}
	
	sort(stu + 1, stu + n + 1, cmp);
	
	for (int i = 1; i <= 5; i ++ )
	{
		cout << stu[i].name << " " << stu[i].score << endl;
	}
	
	return 0;
}
2022/11/10 17:15
加载中...