DIgnited @ 2020-09-13 18:57:48
//P1104
#include<bits/stdc++.h>
#define sc scanf
#define pr printf
using namespace std;
struct student
{
int chinese;
int english;//嘤语
int math;
int num;
int scan;
};
bool cmp(student s,student ss)
{
if(s.num!=ss.num)
return s.num>ss.num;
else if(s.chinese!=ss.chinese)
return s.chinese>ss.chinese;
else if(s.scan!=ss.scan)
return s.scan<ss.scan;
}
int main()
{
student a[301];
int n,i;
sc("%d",&n);
for(i=0;i<n;i++)
{
a[i].num=0;
sc("%d%d%d",&a[i].chinese,&a[i].math,&a[i].english);
a[i].num+=a[i].chinese+a[i].math+a[i].english;
a[i].scan=i+1;
}
sort(a,a+n+1,cmp);
for(int i=0;i<5;i++)
pr("%d %d\n",a[i].scan,a[i].num);
return 0;
}
by metaphysis @ 2020-09-14 10:34:31
@Acceleratorst
sort(a,a+n+1,cmp);
应为:
sort(a,a+n+,cmp);
因为您是从序号0开始读数据的。
错误的原因应该是没有考虑到n<5时的情形,即总人数小于5个人时,有多少人就输出多少人,而不是输出5个。
by DIgnited @ 2020-09-14 19:26:42
@metaphysis 多谢神犇