80,最后一个测试点WA,求助

P5726 【深基4.习9】打分

leowxl @ 2022-08-02 10:54:42

#include<stdio.h>
#include<math.h>
int main(void)
{
    int n, i, j, t, sum;
    double a;
    int m[1000]={0};
    sum = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%d", (m + i));
    }
    for (j = n; j > 0; j--)
    {
        for (i = 0; i <= j; i++)
        {
            if (*(m + i) < *(m + i + 1))
            {
                t = *(m + i);
                *(m + i) = *(m + i + 1);
                *(m + i + 1) = t;
            }
        }
    }
    for (i = 1; i < n - 1; i++)
    {
        sum += *(m + i);
    }
    a = (1.0 * sum) / (1.0 * (n - 2));
    printf("%.2lf", a);
    return 0;
}

by youyi2008 @ 2022-08-02 11:27:59

数组开的不够,把m数组开到1000以上就好了


by leowxl @ 2022-08-02 11:45:50

@youyi2008 谢谢!


|