Fred_gong @ 2023-07-05 22:26:46
#include<bits/stdc++.h>
using namespace std;
struct node {
string name;
int score1;
int score2;
int score3;
};
node a[1005];
int main() {
int n;
cin >> n;
for(int i=1; i<=n; i++) {
cin >> a[i].name >> a[i].score1 >> a[i].score2 >> a[i].score3;
}
int maxT = 0;
int maxI = 0;
for(int i=1; i<=n; i++) {
int t = a[i].score1 + a[i].score2 + a[i].score3;
if(t > maxT) {
maxT = t;
maxI = i;
}
}
cout << a[maxI].name << " " << a[maxI].score1 << " " << a[maxI].score2 << " " << a[maxI].score3 << endl;
return 0;
}
by Fred_gong @ 2023-07-05 22:28:34
本人用打擂台方法 没用sort排序
by Humble_oath @ 2023-07-05 22:33:06
如果有多个总分相同的学生,输出靠前的那位。
by Sqj147 @ 2023-07-09 13:58:08
@Fred_gong
int maxT = -1;//1. 总成绩可能为 0,
//2. 或者默认输出第一组数据,即 i (0 -> n) 或 maxI = 1;
by Soda_mew @ 2023-07-12 14:47:11
有一种可能就是总成绩为0,那这种情况下你的maxT是不是就要 稍作修改了(照着@Sqj147 大佬给你提供的写法改掉就好)