90分是怎么回事呀?求帮忙改一下改,谢谢!

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

Shadow_star @ 2023-10-07 19:54:36


#include<bits/stdc++.h>
using namespace std;
struct stu{
    string bianhao;
    int shu,yu,ying;
};
stu a[10000];
int main(){
    int n,r,t,e,y;
    cin>>n;
    for(int i=1;i<=n;i++){
        r=0;
        cin>>a[i].bianhao;
        cin>>a[i].yu>>a[i].shu>>a[i].ying;
        r+=(a[i].shu+a[i].ying+a[i].yu);
        if(r>t){t=r;e=i;}
    }cout<<a[e].bianhao<<" "<<a[e].yu<<" "<<a[e].shu<<" "<<a[e].ying<<endl;
    return 0;
}

/*明明逻辑是对的,同学分数相同也考虑到了,为什么不能满分呢?求大佬帮忙找一下错误,谢谢!*/

by abensyl @ 2023-10-07 19:57:41

#include<bits/stdc++.h>
using namespace std;
struct stu{
    string bianhao;
    int shu,yu,ying;
};
stu a[10000];
int main(){
    int n,r,t=-1,e,y;
    cin>>n;
    for(int i=1;i<=n;i++){
        r=0;
        cin>>a[i].bianhao;
        cin>>a[i].yu>>a[i].shu>>a[i].ying;
        r+=(a[i].shu+a[i].ying+a[i].yu);
        if(r>t){t=r;e=i;}
    }cout<<a[e].bianhao<<" "<<a[e].yu<<" "<<a[e].shu<<" "<<a[e].ying<<endl;
    return 0;
}

by LiAuPb @ 2023-10-07 19:58:42

如果学生总分都为 0 呢?


by LiAuPb @ 2023-10-07 19:59:08

@DONG_yangmi


by Shadow_star @ 2023-10-07 20:08:58

@LiJingQian 谢谢啊o( ̄▽ ̄)ブ!


by ningyuqi_xin @ 2023-10-11 16:20:53

之前我做的时候也是忽略了都是0的情况

注意:“输出靠前的那位”

(死在第一个点是吧)


|