大佬们能帮忙debug一下吗,WA点在 1 7 10,谢谢!!!

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

ADmark42 @ 2023-10-24 16:53:07

#include <stdio.h>

struct Stu {
    int a, b, c, ans;
    char g[200];
} stu[1000];

int main() {
    int  n, i;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%s %d %d %d", stu[i].g, &stu[i].a, &stu[i].b, &stu[i].c);
        stu[i].ans = 0;
    }
    for (i = 0; i < n; i++) {
        stu[i].ans = stu[i].a + stu[i].b + stu[i].c;
    }
    int max = 0;
    for (i = 0; i < n; i++) {
        if (stu[i].ans > max) {
            max = stu[i].ans;
        }
    }
    for (i = 0; i < n; i++) {
        if (stu[i].ans == max) {
            printf("%s %d %d %d\n", stu[i].g, stu[i].a, stu[i].b, stu[i].c);
        }
    }
}

by Yinsh @ 2023-10-24 16:58:27

如果有相等的,你把多个人都输出了


by Yinsh @ 2023-10-24 16:59:20

当你找到一个人满足

stu[i].ans == max

时,应该结束循环


by ADmark42 @ 2023-10-24 17:01:10

@Yinsh 好的谢谢佬


|