题目链接:http://ybt.ssoier.cn:8088/problem_show.php?pid=1179
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 310;
struct Student
{
int Chinese, math, English;
int id, total;
} stu[N];
bool cmp(const Student &x, const Student &y)
{
if (x.total != y.total)
{
return x.total > y.total;
}
else if (x.Chinese != y.Chinese)
{
return x.Chinese > y.Chinese;
}
else
{
return x.id < y.id;
}
}
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> stu[i].Chinese >> stu[i].math >> stu[i].English;
stu[i].total = stu[i].Chinese + stu[i].math + stu[i].English;
stu[i].id = i;
}
sort(stu + 1, stu + n + 1, cmp);
int cnt = min(5, n);
for (int i = 1; i <= cnt; i++)
{
cout << stu[i].id << " " << stu[i].total << endl;
}
return 0;
}