90分,求大佬帮忙(本人是一名蒟蒻)

P5740 【深基7.例9】最厉害的学生

baixk @ 2024-01-19 19:47:28

#include <bits/stdc++.h>
using namespace std;
int n,a,b,c,sum,maxscore=0,chinese,maths,english;
string s,name;
int main()
{
    cin>>n;
    while(n--)
    {
        cin>>s>>a>>b>>c;
        sum=a+b+c;
        if(sum>maxscore)
        {
            if(sum>maxscore) swap(sum,maxscore);
            chinese=a;
            maths=b;
            english=c;
            name=s;
        } 
    }
    cout<<name<<" "<<chinese<<" "<<maths<<" "<<english;
    return 0;
} 

by Forever_OIer @ 2024-01-19 20:15:13

maxscore初值应该赋成负数,要不然如果所有人总分都是0的话输出不了名字


by Forever_OIer @ 2024-01-19 20:15:34

@kunkun265 求关


|