c语言,全部WA,但自己测试没有问题,求助大佬

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

h135711 @ 2024-12-22 00:28:44

#include <stdio.h>
#include <stdlib.h>
struct Student {
    char name[10];
    int c;
    int m;
    int e;
};
int main()
{
    char ch;
    int n,sum=0,j;
    struct Student *a,*b,*c;
    scanf("%d",&n);
    getchar();
    a = (struct Student*)malloc(sizeof(struct Student)*n);
    b = a;
    c =a;
    for (int i=0;i<n;i++) {
        while((ch = getchar())!=' ') {
            (*a).name[j] = ch;
            j++;
        }
        j = 0;
        scanf("%d",&(a->c));
        scanf("%d",&(a->m));
        scanf("%d",&(a->e));
        if(a->c + a->m + a->e > sum){
            sum = a->c + a->m + a->e;
            b = a;
        }
        getchar();
        a++;
    }
    printf("%s %d %d %d",b->name,b->c,b->m,b->e);
    free(c);
    return 0;
}

|