01bit @ 2020-09-05 17:14:20
#include <cstdio>
#include <algorithm>
using namespace std;
struct student
{
int id;
int Chinese, maths, English;
} stus[300 + 1];
int n;
bool cmp(student a, student b)
{
if (a.Chinese + a.maths + a.English == b.Chinese + b.maths + b.English)
{
if (a.Chinese == b.Chinese)
return a.id < b.id;
return a.Chinese > b.Chinese;
}
return a.Chinese + a.maths + a.English > b.Chinese + b.maths + b.English;
}
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
stus[i].id = i;
scanf("%d%d%d", &(stus[i].Chinese), &(stus[i].maths), &(stus[i].English));
}
sort(&(stus[1]), &(stus[n]), cmp);
for (int i = 1; i <= 5; i++)
printf("%d %d\n", (stus[i].id), (stus[i].Chinese) + (stus[i].maths) + (stus[i].English));
return 0;
}
by する @ 2020-09-05 18:01:46
28行
sort(&(stus[1]), &(stus[n]), cmp);
改成
sort(&(stus[1]), &(stus[n+1]), cmp);
@bit01