为什么第三个测试点过不了?

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

MIDDLEeeeeee @ 2020-12-11 00:25:27

#include <stdio.h>
#include <stdlib.h>
struct student
{
    char name[8];
    int chince ;
    int math;
    int english ;
};
int main()
{
    int mark=0;
    int i;
    int N;
    int sum=0;
    int max=0;
    scanf("%d",&N);
    struct student g[1010];
    for(i=0;i<N;i++)
    {
        sum=0;
        scanf("%s",g[i].name);
        scanf("%d%d%d",&g[i].chince,&g[i].math,&g[i].english);
        sum=g[i].chince+g[i].math+g[i].english;
        if(max<sum)
        {
            max=sum;
            mark=i;
        }

    }
    printf("%s %d %d %d",g[mark].name,g[mark].chince,g[mark].math,g[mark].english);

    return 0;
}

by w23c3c3 @ 2020-12-11 07:33:22

char*数组开大一点就好了,因为最后他会有个字符是\0
Chinese是有e的


by Tianxn @ 2021-01-09 21:00:05

#include <iostream>
using namespace std;

int n, maxi, maxV; 
struct node {
    int a, b, c;
    char s[10];
}f[1005];

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> f[i].s >> f[i].a >> f[i].b >> f[i].c;
        int tmp = f[i].a + f[i].b + f[i].c;
        if (tmp > maxV) maxV = tmp, maxi = i;
    }
    cout << f[maxi].s << " " << f[maxi].a << " " << f[maxi].b << " " << f[maxi].c << endl;
    return 0;
} 

|