救!

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

Hz138588 @ 2020-09-13 13:36:53

不知道为什么错了


#include<bits/stdc++.h>
using namespace std;
struct student{
    string name;
    int C,M,E;
};
void bi(student a,student b){
    if(a.C+a.E+a.M<b.C+b.E+b.M){
        a.name="";a.name=b.name;
        a.C=b.C;a.E=b.E;a.M=b.M;
    }
}
int main(void){
    int N;
    scanf("%d",&N);
    student best;
    for(int i=1;i<=N;i++){
        student stu;
        cin>>stu.name>>stu.C>>stu.M>>stu.E;
        bi(best,stu);
    }
    cout<<best.name<<" "<<best.C<<" "<<best.M<<" "<<best.E<<endl;
    return 0; 
}

by JK_LOVER @ 2020-09-13 13:54:43

@hezhen2009 ||


by JK_LOVER @ 2020-09-13 13:55:13

@hezhen2009 ||

#include<bits/stdc++.h>
using namespace std;
struct student{
    string name;
    int C,M,E;
};
void bi(student &a,student b){
    if(a.C+a.E+a.M<b.C+b.E+b.M){
        a.name=b.name;
        a.C=b.C;a.E=b.E;a.M=b.M;
    }
}
int main(void){
    int N;
    scanf("%d",&N);
    student best ={"0",0,0,0};
    for(int i=1;i<=N;i++){
        student stu;
        cin>>stu.name>>stu.C>>stu.M>>stu.E;
        bi(best,stu);
    }
    cout<<best.name<<" "<<best.C<<" "<<best.M<<" "<<best.E<<endl;
    return 0; 
}

by Hz138588 @ 2020-09-13 14:01:05

@JK_LOVER 感谢dalao


|