Wang_xin_chen @ 2024-07-21 12:24:43
#include<bits/stdc++.h>
using namespace std;
int n;
struct ll{
string name;
int chinese_score,english_score,maths_score,all_score;
}a[1000005];
bool cmp(ll a,ll b){
return a.all_score>b.all_score;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].name>>a[i].chinese_score>>a[i].maths_score>>a[i].english_score;
a[i].all_score=a[i].chinese_score+a[i].english_score+a[i].maths_score+a[i].all_score;
}
sort(a+1,a+n+1,cmp);
cout<<a[1].name<<" "<<a[1].chinese_score<<" "<<a[1].maths_score<<" "<<a[1].english_score<<endl;
return 0;
}
by WEICY123 @ 2024-07-21 15:30:56
@Wang_xin_chen 如果有多个总分相同的学生,输出靠前的那位。 用这题用sort不稳定要使用stable_sort
by 18963033595a @ 2024-07-22 17:12:09
stable_sort(a+1,a+n+1,cmp);