lin_zxy @ 2023-08-17 11:10:29
WA的竟然是第一个测试点,小蒟蒻不理解。。。
#include<bits/stdc++.h>
using namespace std;
int n;
struct student{
string name;
int chinese;
int maths;
int english;
}b,ans;
int main()
{
cin>>n;
for(int i=1;i<=n;++i) {
cin>>b.name>>b.chinese>>b.maths>>b.english;
if((b.chinese+b.english+b.maths)>(ans.chinese+ans.english+ans.maths)){
ans=b;
}
}
cout<<ans.name<<" "<<ans.chinese<<" "<<ans.maths<<" "<<ans.english<<endl;
return 0;
}
by C202301 @ 2023-08-17 11:14:52
有没有考虑所有人的语数英成绩都是0。
by C202301 @ 2023-08-17 11:18:08
@lin_zxy
by lao_wang @ 2023-08-17 11:19:13
用sort岂不更好
by lin_zxy @ 2023-08-17 11:31:55
@C202301 谢谢,请问是不是设个初始值
int chinese=-1;
int maths=-1;
int english=-1;
就可以了
by lin_zxy @ 2023-08-17 11:32:42
@C202301 AC了,谢谢 已关注