求助!!!

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

ZBXALQX @ 2024-06-15 09:56:41

原本下载了一下#1

1
dingjunwei 0 0 0

这个代码按理来说应该可以过的。

#include<bits/stdc++.h>
using namespace std;
int main(){
    string name,name1;
    int n,a,b,c,sum=0,a1,b1,c1;
    cin>>n;
    for(int i=1;i<=n;i++){
    cin>>name>>a>>b>>c;
    if(n==1&&a+b+c==0){
    cout<<name<<" 0 0 0 ";
    return 0;
    }
    else if(a+b+c>sum){
        sum=a+b+c;
            name1=name;
                a1=a;
                b1=b;
            c1=c;
        }
    }
    cout<<name1<<" "<<a1<<" "<<b1<<" "<<c1;
    return 0;
}

可是...
为什么!!!


by ZBXALQX @ 2024-06-15 09:58:35

代码中#1的解决办法:

    if(n==1&&a+b+c==0){
    cout<<name<<" 0 0 0 ";
    return 0;
    }//还是过不了

by ZBXALQX @ 2024-06-15 10:20:00

@jiangyunuo


by L_V_ @ 2024-06-15 10:25:45

@ZBXALQX 菜,就多练

#include<bits/stdc++.h>
using namespace std;
int n,a[1005],b[1005],c[1005],m,a1,b1,c1,d;
string p[1005],o; 
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>p[i]>>a[i]>>b[i]>>c[i];
    }
    for(int i=n;i>=1;i--){
        m=a[i]+b[i]+c[i];
        if(m>=d){
            d=m;
            a1=a[i];
            b1=b[i];
            c1=c[i];
            o=p[i];
        }
    }
    cout<<o<<" "<<a1<<" "<<b1<<" "<<c1;
}

by ZBXALQX @ 2024-06-15 10:26:42

@lvrunzi 不是,你干嘛


by ZBXALQX @ 2024-06-15 10:27:21

@lvrunzi 看不懂,一点都看不懂


by L_V_ @ 2024-06-15 10:28:15

AC的


by ZBXALQX @ 2024-06-15 10:30:28

@lvrunzi e...


by L_V_ @ 2024-06-15 10:30:45

m是总分,o是(最牛逼)最厉害的人的名字


by jiangyunuo @ 2024-06-15 14:17:18

@ZBXALQX 看这

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,ans=1,maxx=0;
    cin>>n;
    string a[n+1];
    int b[n+1],c[n+1],d[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        if(b[i]+c[i]+d[i]>maxx){maxx=b[i]+c[i]+d[i];ans=i;}
    }
    cout<<a[ans]<<" "<<b[ans]<<" "<<c[ans]<<" "<<d[ans]<<endl;
return 0;
}

by ZBXALQX @ 2024-06-15 14:21:30

@jiangyunuo 三克油


| 下一页