0分求助!

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

Ghy_boy @ 2023-12-24 11:37:30

#include<bits/stdc++.h>
#define RETURN return
using namespace std;
struct studend{
    string name;
    int y,s,yai,de,id;
};
int main()
{
    string name1;
    int age=-100000,y2,s2,t3;
    int a;
    cin>>a;
    studend pai[a];
    for(int i=0;i<a;i++){
        cin>>pai[i].name>>pai[i].y>>pai[i].s>>pai[i].yai;
        pai[i].de+=pai[i].y+pai[i].s+pai[i].yai;
        pai[i].id=i;
        if(age<pai[i].de){
            swap(age,pai[i].de);
            swap(y2,pai[i].y);
            swap(s2,pai[i].s);
            swap(t3,pai[i].yai);
            swap(name1,pai[i].name);
        }
    }
    cout<<name1<<" "<<y2<<" "<<s2<<" "<<t3;
RETURN 0;
}

为什么样例可以过,检测全WA?


by vzcx_host @ 2023-12-24 11:52:22

全局数组是习惯


by arvin_guo @ 2023-12-24 12:19:44

#include <bits/stdc++.h>
using namespace std;
struct exam
{
    string name;
    int Cscore;
    int Mscore;
    int Escore;
    int T;
};
int main()
{
    int n;
    cin>>n;
    exam arr[n];
    for (int x = 0;x < n;x++)
    {
        cin>>arr[x].name>>arr[x].Cscore>>arr[x].Mscore>>arr[x].Escore;
        arr[x].T=arr[x].Cscore+arr[x].Mscore+arr[x].Escore;
    }

    int max=0;
    int index = 0;
    for (int y = 0;y < n;y++)
    {
        if (arr[y].T > max)
        {
            index=y;
            max=arr[y].T;
        }
    }
    cout<<arr[index].name<<' '<<arr[index].Cscore<<' '<<arr[index].Mscore<<' '<<arr[index].Escore;
    return 0;
}

|