90分,第一个WA

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

L19070850630 @ 2024-12-01 22:21:52

#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<math.h>

typedef struct Student {
    char name[20];
    int Chinese;
    int Math;
    int English;
}Student;
int main(void) {
    int n;
    scanf("%d", &n);
    Student* student = (Student*)malloc(sizeof(Student) * n);
    int* sum = (int*)calloc(n, sizeof(int));
    int max = 0;
    int place;
    for (int i = 0; i < n; i++) {
        scanf("%s %d %d %d", &student[i].name, &student[i].Chinese, &student[i].Math, &student[i].English);
        sum[i] = student[i].Chinese + student[i].Math + student[i].English;
        if (sum[i] > max) { max = sum[i], place = i; }

    }
    printf("%s %d %d %d", student[place].name, student[place].Chinese, student[place].Math, student[place].English);

    return 0;
}

by L19070850630 @ 2024-12-01 22:23:33

不用了,已经过了


by L19070850630 @ 2024-12-01 22:24:21

记得考虑所有人都是0分得情况


|