Run ID:59515

提交时间:2023-10-29 13:58:38

#include<iostream> using namespace std; int n; struct Stu{ int chinese,math,english; int id; int sum; }stu[305]; bool cmp(Stu a,Stu b){ if(a.sum<b.sum){ return true; }else{ if(a.sum==b.sum){ if(a.chinese<b.chinese){ return true; }else{ if(a.chinese==b.chinese){ return a.id>b.id; }else{ return false; } } }else{ return false; } } } int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>stu[i].chinese>>stu[i].math>>stu[i].english; stu[i].sum=stu[i].chinese+stu[i].math+stu[i].english; stu[i].id=i; } for(int i=1;i<=n-1;i++){ for(int j=1;j<=n;j++){ if(cmp(stu[j],stu[j+1])){ swap(stu[j],stu[j+1]); } } } for(int i=1;i<=5;i++){ cout<<stu[i].id<<" "<<stu[i].sum<<endl; } return 0; }