大赛评分
某大赛有n(n>=5)个选手参赛,m(m>=4)个评委依次为参赛的选手评判打分;最高10分,最低0分。统分规则为:每个选手所得的m个评分中,去掉一个最高分,去掉一个最低分,然后平均该选手的最后得分。根据n个选手的最后得分从高到低排出名次表,以便确定获奖名单。
#include <stdio.h> #define PLAYER_MAX 100 #define JUDGE_MAX 99 typedef struct { int id; float score[JUDGE_MAX]; float final_score; } Player; void select_sort_desc(Player * players, int size) { int i, j, k; for(i = 0; i < size - 1; i++) { k = i; for(j = i + 1; j < size; j++) { if(players[k].final_score < players[j].final_score) { k = j; } } if(k != i) { Player temp = players[k]; players[k] = players[i]; players[i] = temp; } } } int main(void) { Player players[PLAYER_MAX]; int n, m, i, j; float sum, min, max; printf("请输入选手个数:"); fflush(stdout); while(!scanf("%d", &n) || n < 5) { printf("请输入选手个数:"); fflush(stdout); } printf("请输入评委个数:"); fflush(stdout); while(!scanf("%d", &m) || m < 4) { printf("请输入评委个数:"); fflush(stdout); } for(i = 0; i < n; i++) { printf("请输入%d号选手得分(0 -- 10),得分请用空格分开:\n", i + 1); for(j = 0; j < m; j++) { scanf("%f", players[i].score + j); if(players[i].score[j] < 0 || players[i].score[j] > 10) { printf("输入有误!\n"); i--; break; } players[i].id = i + 1; } } for(i = 0; i < n; i++) { sum = 0; min = 10; max = 0; for(j = 0; j < m; j++) { (max < players[i].score[j]) && (max = players[i].score[j]); (min > players[i].score[j]) && (min = players[i].score[j]); } for(j = 0; j < m; j++) sum += players[i].score[j]; sum -= max + min; players[i].final_score = sum / (m - 2); } select_sort_desc(players, n); for(i = 0; i < n; i++) printf("第 %d 名是 %d 号选手,得分是:%.2f\n", i + 1, players[i].id, players[i].final_score); return 0; }