Zhouyuhan_1125 @ 2022-10-02 12:03:32
#include <bits/stdc++.h>
using namespace std;
struct stu{
string name;
int yu,shu,yin;
int zong;
};
stu a[1005];
bool cmp(stu x,stu y){
if(x.zong != y.zong) return x.zong > y.zong;
}
int main(){
int n;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i].name;
cin >> a[i].yu;
cin >> a[i].shu;
cin >> a[i].yin;
a[i].zong = a[i].yu + a[i].shu + a[i].yin;
}
sort(a + 1,a + n + 1,cmp);
cout << a[1].name << " " << a[1].yu << " " << a[1].shu << " " << a[1].yin;
return 0;
}
by DiruiXiao @ 2022-10-02 12:12:37
如果有多个总分相同的学生,输出靠前的那位。
总分相同时,按输入顺序输出...
by DiruiXiao @ 2022-10-02 12:18:39
记录一个id,当总分相同时以id排序
by Kevin_wbc @ 2022-10-24 21:20:23
试试用擂台法