90分蒟蒻求助

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

kkkSb_O3 @ 2023-10-01 16:10:33

#include<bits/stdc++.h>
using namespace std;
int q,w,w2,n,v,b;
string w3;
struct qqq
{
    string n;
    int c,e,m;
}a;
int main()
{
    cin>>q;
    for(int i=1;i<=q;i++)
    {
        cin>>a.n>>a.c>>a.e>>a.m;
        w=a.c+a.m+a.e;
        if(w>w2)
        {
            w2=w;
            w3=a.n;
            v=a.c;
            b=a.e;
            n=a.m;
        }
    }
    cout<<w3<<' '<<v<<' '<<b<<' '<<n;
    return 0;
}

by 15093432132cqt @ 2023-10-02 21:08:17

我知道你做过了,但你——

还是看看我的代码吧

#include<bits/stdc++.h>
using namespace std;
int n;
struct student{
    string name;
    int c=-1;
    int m=-1;
    int e=-1; 
}b,ans;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>b.name>>b.c>>b.m>>b.e;
        if((b.c+b.e+b.m)>(ans.c+ans.e+ans.m)){
            ans=b;
        }
    }
    cout<<ans.name<<" "<<ans.c<<" "<<ans.m<<" "<<ans.e<<endl;
    return 0;
}

|