90分qz

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

pjxsyxx @ 2024-11-02 12:56:18

#include<bits/stdc++.h>
using namespace std;
struct student{
    char name[9];
    int yw;
    int sx;
    int yy;
};
int main(){
    int n,max=0,t;
    cin>>n;
    student a[n];
    for(int i=0;i<n;i++){
        cin>>a[i].name>>a[i].yw>>a[i].sx>>a[i].yy;
    }
    for(int i=0;i<n;i++){
        int zf=a[i].sx+a[i].yw+a[i].yy;
        if(zf>max){
            max=zf;
            t=i;
        }
    }
    cout<<a[t].name<<" "<<a[t].yw<<" "<<a[t].sx<<" "<<a[t].yy;
    return 0;
}

为什么1是RE???????????


by guer_loser_lcz @ 2024-11-02 13:00:41

@pjxsyxx 把name由char改成string或改成二十的空间试试。


by pjxsyxx @ 2024-11-02 13:22:19

都试过了,一个还是RE,一个Compile Error


by Eason20120229 @ 2024-11-02 13:36:00

@pjxsyxx 不要用动态数组,直接把数组放在全局,开1000的大小。 max初始化为-1


by Eason20120229 @ 2024-11-02 13:37:10

@pjxsyxx 帮你调好了

#include <bits/stdc++.h>
using namespace std;
struct student {
    char name[9];
    int yw;
    int sx;
    int yy;
};
student a[1000];
int main() {
    int n;
    int max = -1;
    int t;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i].name >> a[i].yw >> a[i].sx >> a[i].yy;
    }
    for (int i = 0; i < n; i++) {
        int zf = a[i].sx + a[i].yw + a[i].yy;
        if (zf > max) {
            max = zf;
            t = i;
        }
    }
    cout << a[t].name << " " << a[t].yw << " " << a[t].sx
         << " " << a[t].yy;
    return 0;
}

by pjxsyxx @ 2024-11-02 16:54:04

已AC,谢谢!!!!!!!!!


|