60分求助,自己推断可能是整型或者浮点型转化有问题
查看原帖
60分求助,自己推断可能是整型或者浮点型转化有问题
1572449
SakuraFubuki楼主2024/12/22 11:27

代码如下。在跑题目给出的样例时没有出错,能够正确输出。求大佬斧正!

#include <bits/stdc++.h>

void clear(int score[], int size) {
    for (int i = 0; i < size; i++) {
        score[i] = 0;
    }
}

int main(void) {
    int n, m;
    scanf("%d %d", &n, &m);

    int score[1000];
    int student[1500];
    int cnt = 0;
    double total;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            scanf("%d", &score[j]);
        }

        int max = *std::max_element(score, score + m);
        int min = *std::min_element(score, score + m);
        int sum = std::accumulate(score, score + m, 0) - max - min;
        total = (sum) / (m - 2);
        student[cnt++] = (total);
        clear(score, m);
    }

    double maxx = *std::max_element(student, student + cnt);
    printf("%.2lf\n", maxx);
    return 0;
}

2024/12/22 11:27
加载中...