这个怎么做啊??
编写演讲比赛评分程序,假定有10个选手,5个评委,选手的得分是去掉一个最高分和一个最低分的平均分。计算出每个选手的平均分,并按从高分到低分的顺序输出所有选手的得分
#include <stdio.h> #define PLAYER 10 #define REFEREE 5 float calc_score(float *score, int count) { float sum = 0; int i, j, tmp; /* 冒泡排序(从大到小) */ for (i = 0; i < count - 1; i++) { for (j = i + 1; j < count; j++) { if (score[i] < score[j]) { tmp = score[i]; score[i] = score[j]; score[j] = tmp; } } } /* 平均分 */ for (i = 1; i < count - 1; i++) { sum += score[i]; } return sum / (count - 2); } typedef struct _player_score { int number; float score; } player_score_t; int main(void) { int i, j, index = 1; float referee_score[REFEREE]; player_score_t player_score[PLAYER]; /* 输入 评分 */ for (i = 0; i < PLAYER; i++) { printf("请输入 %2d 号选手得分:\n", i + 1); for (j = 0; j < REFEREE; j++) { printf(" 裁判 %2d 判分: ", j + 1); scanf("%f", &referee_score[j]); } player_score[i].number = i + 1; player_score[i].score = calc_score(referee_score, REFEREE); } /* 选手排序(冒泡) */ for (i = 0; i < PLAYER - 1; i++) { for (j = i + 1; j < PLAYER; j++) { player_score_t tmp; if (player_score[i].score < player_score[j].score) { tmp.number = player_score[i].number; tmp.score = player_score[i].score; player_score[i].number = player_score[j].number; player_score[i].score = player_score[j].score; player_score[j].number = tmp.number; player_score[j].score = tmp.score; } } } /* 显示成绩 */ printf("==== 成绩:\n"); for (i = 0; i < PLAYER; i++) { if (i > 0 && player_score[i].score != player_score[i - 1].score) {/* 非并列, 增加名次 */ index = i + 1; } printf(" 第 %2d 名: 选手 %2d 成绩 %.1f\n", index, player_score[i].number, player_score[i].score); } return 0; }
#include <stdio.h> int main() { double xs[10] = {0}, min, max, t; int i, j; for (i = 0; i < 10; i++) { min = 101; //假定最高分是100 max = -1; //最低分0 for (j = 0; j < 5; j++) { scanf("%lf", &t); if (t > max) max = t; if (t < min) min = t; xs[i] += t; } xs[i] -= min + max; xs[i] /= 3; } for (i = 0; i < 9; i++) { for (j = i; j < 10; j++) { if (xs[i] < xs[j]) { t = xs[i]; xs[i] = xs[j]; xs[j] = t; } } } for (i = 0; i < 10; i++) printf("%lf\n", xs[i]); }
[此贴子已经被作者于2022-10-18 12:29编辑过]