为什么第三个测试点是错的,大佬们

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

18270912837xjx @ 2022-12-07 18:17:17


#include<stdio.h>
int main()
{
    int n,i,max,j;
    scanf("%d",&n);
    struct A
    {
        char name[8];
        int china,math,english,sum;
    };
    struct A student[1010];
    for(i=1;i<=n;i++)
    {
        scanf("%s %d %d %d",student[i].name,&student[i].china,&student[i].math,&student[i].english);
       student[i].sum= student[i].china+student[i].math+student[i].english;

    }
    max=student[1].sum;
    j=1;
    for(i=1;i<=n;i++)
    {
        if(student[i].sum>max)
        {max=student[i].sum;
        j=i;
        }

    }
    printf("%s %d %d %d",student[j].name,student[j].china,student[j].math,student[j].english);

    return 0;
}

by LWY9527 @ 2022-12-28 16:13:14

把结构体里char[8]的8改成9就ac了,char[8]的存储位置是0 1 2 3 4 5 6 7八个,但是名字长度最长可以是8个,所以姓名这个字符数组至少要开到9


|