全wa 求助

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

asDest @ 2021-12-12 20:24:23

#include<stdio.h>
int main()
{
    int N,i,j,k,l;
    scanf("%d",&N);
    char qq;
    qq=getchar();
    struct stu
    {
        char a[9];
        int  c,e,m;
    }stu[1000];
    int t[N];
    for(i=0;i<N;i++)
    {   
        j=0;
        while((stu[i].a[j]=getchar())!=32)
        j++;
        stu[i].a[j]='\0';
        scanf("%d%d%d",&stu[i].c,&stu[i].e,&stu[i].m);
        t[i]=stu[i].c+stu[i].e+stu[i].m;
    }
    for(i=1,l=0,k=t[0];i<N;i++)
        if(k<t[i])
        {
            k=t[i];
            l=i;
        }
    printf("%s %d %d %d",stu[l].a,stu[l].c,stu[l].e,stu[l].m);
    return 0;
}

by asDest @ 2021-12-12 20:25:10

哎,判例在devc++上是对的呀,疑惑。


by FanSizhe127 @ 2021-12-16 12:59:42

#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long a[10005],b[10005],c[10005],n,max1=-9099990,max2=-9099990,max3=-9099990;
    string s[10005],m;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>s[i]>>a[i]>>b[i]>>c[i];
    for(int i=1;i<=n;i++)
    {
        if(a[i]+b[i]+c[i]>max1+max2+max3)
        {
            max1=a[i];
            max2=b[i];
            max3=c[i];
            m=s[i];
        }
    }
    cout<<m<<' '<<max1<<' '<<max2<<' '<<max3;
}

by zhanghanwen1112 @ 2022-04-08 14:54:00

#include<bits/stdc++.h>
using namespace std;
struct student
{
    string name;
    int c,m,e,chenji;
}
a[1000];
int main()
{
    int n,p;
    cin>>n;
    for(int i=0;i<=n;i++)
    {
        cin>>a[i].name;
        cin>>a[i].c>>a[i].m>>a[i].e;
        a[i].chenji=a[i].c+a[i].m+a[i].e; 
    }
    for(int i=0;i<=n-1;i++)
    {
     for(int j=i+1;j<=n-1;j++)
     {
        if(a[j].chenji>a[i].chenji)
        {
            swap(a[j],a[i]);
         }
         if(a[j].chenji==a[i].chenji)
         {
            if(a[j].name<a[i].name)
            {
                swap(a[j],a[i]);
             }
         }
     }
    }
        cout<<a[0].name<<" "<<a[0].c<<" "<<a[0].m<<" "<<a[0].e;
    return 0;
}

|