评委评分

在歌星大奖赛中,有 10 个评委为参赛的选手打分,分数为 1~100 分。选手最后得分为:去掉一个最高分和一个最低分后其余 个分数的平均值。请编写一个程序实现。题目条件不变,但考虑同时对评委评分进行裁判,即在 10 个评委中找出最公平和最不公平 

#include <stdio.h>

#define MAXN	10

int main(void)
{
	float score[MAXN] = {0.0};
	float a[MAXN];
	float average;
	float max, min, temp, sum;
	int i;
	int p, q;
	
	max = -1;	
	min = 101;
	sum = 0;
	
	for (i=0; i<MAXN; ++i) {
		printf("第%d个评委给分(0--100):", i+1);
		scanf("%f", &temp);
		if (temp < 0 || temp > 100) {
			--i;
			continue;
		}
		if (temp > max)
			max = temp;
		if (temp < min)
			min = temp;
		sum += temp;
		score[i] = temp;
	}
	
	printf("去掉一个最高分:%f\n", max);
	printf("去掉一个最低分:%f\n", min);
	sum -= (max + min);
	average = sum / (MAXN - 2);
	printf("选手最后得分:%f\n", average);
	
	max = -1;
	min = 101;
	for (i=0; i<MAXN; ++i) {
		a[i] = average - score[i];
		a[i] = a[i] > 0 ? a[i] : -a[i];
		if (a[i] != 0 && a[i] > max) {
			max = a[i];
			p = i;
		}
		if (a[i] != 0 && a[i] < min) {
			min = a[i];
			q = i;
		}
	}
	
	printf("最公平的评委为第%d位评委,给出的分数为%f\n", q+1, score[q]);
	printf("最不公平的评委为第%d位评委,给出的分数为%f\n", p+1, score[p]);
	return 0;
}	


你可能感兴趣的:(float)