n个评委评分,m个选手参赛,计算并输出参赛选手的最后得分。计算方法为去 除一个最高分和一个最低分,其余的进行平均,得出参赛选手的最后得分。按从大到小的顺序输出参赛选手的最后得分。用c语言程序准确解答
时间: 2024-12-24 09:25:42 浏览: 46
在 C 语言中,你可以使用数组和循环结构来实现这个功能。这里是一个简单的示例程序,假设分数存储在一个二维数组中,每个元素对应一个评委给一个选手的评分:
```c
#include <stdio.h>
#include <stdlib.h>
#define NUM_JUDGES 5 // 判员人数
#define NUM_CONTESTANTS 3 // 参赛者人数
void calculateScores(int judges[][NUM_JUDGES], int* contestants, int numContestants) {
// 初始化临时数组存放去掉最高分和最低分后的成绩
int tempScores[numContestants];
int maxScore, minScore;
for (int i = 0; i < numContestants; i++) {
maxScore = -1;
minScore = INT_MAX; // 初始化为最大整数防止溢出
// 找出当前选手的最高分和最低分
for (int j = 0; j < NUM_JUDGES; j++) {
if (judges[i][j] > maxScore)
maxScore = judges[i][j];
if (judges[i][j] < minScore)
minScore = judges[i][j];
}
// 去掉最高分和最低分,取平均值
int sum = 0;
for (int j = 0; j < NUM_JUDGES; j++) {
if (judges[i][j] != maxScore && judges[i][j] != minScore)
sum += judges[i][j];
}
tempScores[i] = sum / (NUM_JUDGES - 2); // 假设至少有两个评委打分
}
// 按降序排列得分并打印
for (int i = 0; i < numContestants - 1; i++) {
for (int j = i + 1; j < numContestants; j++) {
if (tempScores[j] > tempScores[i]) {
int temp = tempScores[i];
tempScores[i] = tempScores[j];
tempScores[j] = temp;
}
}
}
printf("参赛选手得分(从高到低):\n");
for (int i = 0; i < numContestants; i++) {
printf("%d. %d\n", i+1, tempScores[i]);
}
}
int main() {
// 假设你已经有了一个2D数组,例如评委和选手的分数
int judges[NUM_JUDGES][NUM_CONTESTANTS] = {
{85, 90, 92, 88, 91},
{78, 86, 87, 84, 85},
{93, 94, 91, 92, 90}
};
int contestants[NUM_CONTESTANTS] = {0};
calculateScores(judges, contestants, NUM_CONTESTANTS);
return 0;
}
```
阅读全文
相关推荐


















