题目
代码如下:
#include<bits/stdc++.h>
using namespace std;
int n;
struct stu//结构体
{
int num;
int c,m,e;
int sum;
}student[310];
bool cmp(stu a,stu b)
{
if(a.sum>b.sum)return 1;
else if(a.sum<b.sum)return 0;
else
{
if(a.c>b.c)return 1;
else if(a.c<b.c)return 0;
else
{
if(a.num>b.num)return 0;
else return 1;
}
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++)
{
student[i].num=i;
cin>>student[i].c>>student[i].m>>student[i].e;
student[i].sum=student[i].c+student[i].m+student[i].e;
}
sort(student+1,student+n+1,cmp);//排序
for(int i=1;i<=5;i++)cout<<student[i].num<<" "<<student[i].sum<<endl;
return 0;
}