提交时间:2024-12-27 15:23:23

运行 ID: 329976

#include<bits/stdc++.h> using namespace std; struct stu { int id,chi,mat,eng,tot; }a[305]; bool comp(stu x,stu y) { if(x.tot!=y.tot) return x.tot>y.tot; if(x.chi!=y.chi) return x.chi>y.chi; return x.id<y.id; } void quicksort(int L,int R) { int i,j; stu x; i=L;j=R;x=a[(i+j)/2]; while(i<=j) { while(comp(a[i],x)) i++; while(comp(x,a[j])) j--; if(i<=j) { stu t=a[i];a[i]=a[j];a[j]=t; i++; j--; } } if(L<j) quicksort(L,j); if(i<R) quicksort(i,R); } int main() { int n; cin>>n; for(int i=1;i<=n;i++) { a[i].id=i; cin>>a[i].chi>>a[i].mat>>a[i].eng; a[i].tot=a[i].chi+a[i].mat+a[i].eng; } quicksort(1,n); for(int i=1;i<=5;i++) cout<<a[i].id<<" "<<a[i].tot<<endl; return 0; }