#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
double calculateScore(int scores[], int numJudges) {
double sum = 0;
int minIndex = 0, maxIndex = 0;
for (int i = 1; i < numJudges; i++) {
if (scores[i] < scores[minIndex]) {
minIndex = i;
}
if (scores[i] > scores[maxIndex]) {
maxIndex = i;
}
}
for (int i = 0; i < numJudges; i++) {
if (i != minIndex && i != maxIndex) {
sum += scores[i];
}
}
return sum / (numJudges - 2);
}
int main() {
int n, m;
printf("请输入参赛同学的人数 n 和评委的人数 m(以空格分隔):");
scanf("%d %d", &n, &m);
double highestScore = 0;
for (int i = 0; i < n; i++) {
int* scores = (int*)malloc(m * sizeof(int));
if (scores == NULL) {
fprintf(stderr, "内存分配失败\n");
return 1;
}
printf("请输入第 %d 位同学的 %d 个评分:", i + 1, m);
for (int j = 0; j < m; j++) {
scanf("%d", &scores[j]);
}
double currentScore = calculateScore(scores, m);
if (currentScore > highestScore) {
highestScore = currentScore;
}
free(scores);
}
printf("得分最高的同学的分数为:%.2lf\n", highestScore);
return 0;
}