Run ID:45562

提交时间:2023-03-25 16:55:43

#include<iostream> #include<algorithm> using namespace std; struct student { float id; float c; float m; float e; float tot; }; bool cmp(student a ,student b) { if(a.tot != b.tot ) { return a.tot >b.tot ; } else if(a.c != b.c ) { return a.c>b.c; } else if(a.id != b.id ){ return a.id <b.id ; } } student a[301]; int main() { int n; cin>>n; for(int i=0; i<n; i++) { cin>>a[i].c>>a[i].m>>a[i].e; a[i].id =i+1; a[i].tot =a[i].c +a[i].e +a[i].m ; } sort(a+0,a+n,cmp); for(int i=0; i<5; i++) { cout<<a[i].id <<" "<<a[i].tot <<endl; } }