9个re 一个过了 大佬救命

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

oulu @ 2024-11-09 09:14:49

#include<stdio.h>
int sort(int sum[],int n) 
{
    int max = sum[0];
    int max_number= 0;
    for (int i = 0; i < n; i++)
    {
        if (sum[i] > max)
        {
            max = sum[i];
            max_number = i;
        }
    }
    return max_number;
}
int main()
{
    int n; 
    int m;
    int sum[1000] = { 0 };
    scanf("%d", &n);
    int i, j;
    int score[3][1000];
    int name[10][1000];
    for (i = 0; i < n; i++)
    {
        scanf("%s", &name[i]);
        for (j= 0; j < 3; j++)
        {
            scanf("%d", &score[j][i]);
            sum[i] += score[j][i];
        }
    }
    m = sort(sum, n);
    printf("%s %d %d %d",name[m],score[0][m],score[1][m],score[2][m]);
    return 0;
}

by James_he @ 2024-11-09 09:37:06

可能是main里面数组开太大了,换成全局试试


by oulu @ 2024-11-09 09:42:16

@James_he 还是超时 寄


by 4399__ @ 2024-11-09 20:36:25

re不是超时,是数组越界了。。。


by 4399__ @ 2024-11-09 20:43:55

其实我更好奇为什么%s能输出int类型的name


by oulu @ 2024-11-10 11:11:33

@4399__ @4399__ 给我唐完了


by oulu @ 2024-11-10 11:12:02

ok了感谢各位


|