编制歌手大奖赛评分程序,评委人数及评委的打分均从键盘输入,去掉一个最高分,去掉一个最低分,求选手的最后得分(平均分),不允许用数组用C语言编写
时间: 2024-11-29 19:17:49 浏览: 9
举办歌手大奖赛。-C++程序设计PPT
在C语言中,你可以使用结构体来存储评委信息,并通过循环结构来实现这个评分程序。以下是简化的示例代码:
```c
#include <stdio.h>
// 定义评委结构体
typedef struct {
int id; // 评委编号
int score; // 打分
} Judge;
int main() {
int judge_count;
printf("请输入评委人数:");
scanf("%d", &judge_count);
Judge judges[judge_count]; // 临时数组存储评委信息
for (int i = 0; i < judge_count; ++i) {
printf("请输入评委 %d 的打分:", i + 1);
scanf("%d", &judges[i].score);
}
// 排序并去除最高分和最低分
int sorted_indices[judge_count];
for (int i = 0; i < judge_count; ++i) {
sorted_indices[i] = i;
}
for (int i = 0; i < judge_count - 1; ++i) {
for (int j = 0; j < judge_count - i - 1; ++j) {
if (judges[j].score > judges[j + 1].score) {
int temp = sorted_indices[j];
sorted_indices[j] = sorted_indices[j + 1];
sorted_indices[j + 1] = temp;
}
}
}
int sum = 0;
for (int i = 2; i < judge_count; ++i) { // 开始于第三个元素,因为要去掉两个极端分数
sum += judges[sorted_indices[i]].score;
}
double average_score = (double)sum / (judge_count - 2); // 最终平均分
printf("选手的最后得分为:%.2f\n", average_score);
return 0;
}
阅读全文