galfth @ 2021-03-12 20:54:20
第二个wa
#include<bits/stdc++.h>
using namespace std;
struct student
{
string name;
int chinese,math,english,total;
}a[1001];
int main()
{
int n,max;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i].name>>a[i].chinese>>a[i].math>>a[i].english;
for(int i=1;i<=n;i++)
{
a[i].total=a[i].chinese+a[i].math+a[i].english;
if(max<a[i].total)max=a[i].total;
}
for(int i=1;i<=n;i++)
{
if(max==a[i].total)cout<<a[i].name<<" "<<a[i].chinese<<" "<<a[i].math<<" "<<a[i].english;
}
return 0;
}
by Eason_AC @ 2021-03-12 20:57:22
if(max==a[i].total)cout<<a[i].name<<" "<<a[i].chinese<<" "<<a[i].math<<" "<<a[i].english;
这一行,如果有多个相等的最高分,输出靠前的那一个,你这一行没有体现出来。改成:
if(max==a[i].total){cout<<a[i].name<<" "<<a[i].chinese<<" "<<a[i].math<<" "<<a[i].english;return 0;}
@ybtur
by galfth @ 2021-03-13 21:11:57
@Eason_AC 谢谢,问题解决了。
跪谢跪谢。