zephy3657 @ 2024-08-24 12:52:29
#include <iostream>
#include <string>
using namespace std;
struct student {
string name;
int chinese, math, english;
} a, ans;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a.name >> a.chinese >> a.math >> a.english;
if(a.chinese + a.math + a.english > ans.chinese + ans.math + ans.english)
ans = a;
}
cout<<ans.name<<" "<<ans.chinese<<" "<<ans.math<<" "<<ans.english<<endl;
return 0;
}
by 2022dyx @ 2024-08-24 12:57:03
#include <string>
using namespace std;
struct student {
string name;
int chinese, math, english;
} a, ans;
int main() {
int n;
cin >> n;
ans.math = -1; //如果只有一个人,他每科都是0分,你的ans就不会更新
for (int i = 1; i <= n; i++) {
cin >> a.name >> a.chinese >> a.math >> a.english;
if(a.chinese + a.math + a.english > ans.chinese + ans.math + ans.english)
ans = a;
}
cout<<ans.name<<" "<<ans.chinese<<" "<<ans.math<<" "<<ans.english<<endl;
return 0;
}
by Xingyi_2014 @ 2024-08-29 18:22:38
嗯,对。那怎么修改呢?