Phoebe_n @ 2022-01-15 23:02:02
#include<bits/stdc++.h>
using namespace std;
struct student{
string name;
int chinese,math,english;
}a,ans;
int main(){
int n;
cin>>n;
for(int i=0;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 ssxvngn @ 2022-01-15 23:25:23
@Phoebe_n 那你的去试了一下,第一个点分数全是
#include<bits/stdc++.h>
using namespace std;
struct student{
string name;
int chinese,math,english;
}a,ans;
int main(){
int n;
cin>>n;
ans.chinese=-1,ans.math=-1,ans.english=-1;\\加上这句
for(int i=0;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 endprophet @ 2022-01-16 13:05:44
就是说有可能全部学生都是0分,如果这样的话答案结构体的名字没法更新
by Phoebe_n @ 2022-01-16 22:13:47
@一个pupil 谢谢❤