zhang33 @ 2024-11-14 16:13:52
#include <bits/stdc++.h>
using namespace std;
int n;
struct student{
string name;
int chineses,math,english;
}now,top;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>now.name>>now.chineses>>now.math>>now.english;
if(now.chineses>>now.english>>now.math>top.chineses+top.english+top.math||i==1){
top=now;
}
}
cout<<top.name<<" "<<top.chineses<<" "<<top.math<<" "<<top.english;
return 0;
}
by Pure_Echo @ 2024-11-14 16:36:43
@zhang33你这个判断有问题
by Pure_Echo @ 2024-11-14 16:38:07
你要考虑到判断的符号优先级问题
#include <bits/stdc++.h>
using namespace std;
int n;
struct student{
string name;
int chineses,math,english;
}now,top;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>now.name>>now.chineses>>now.math>>now.english;
if((now.chineses+now.english+now.math>top.chineses+top.english+top.math)||i==1){
top=now;
}
}
cout<<top.name<<" "<<top.chineses<<" "<<top.math<<" "<<top.english;
return 0;
}