Problem Description
青年歌手大奖赛中,评委会给参赛选手打分。选手得分规则为去掉一个最高分和一个最低分,然后计算平均得分,请编程输出某选手的得分。
Input
输入数据有多组,每组占一行,每行的第一个数是n(2<n<=100),表示评委的人数,然后是n个评委的打分。
Output
对于每组输入数据,输出选手的得分,结果保留2位小数,每组输出占一行。
Sample Input
3 99 98 97
4 100 99 98 97
Sample Output
98.00
98.50
代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int i,n;
double s;
while(scanf("%d",&n)==1)
{
if(n<=2||n>100)
break;
double a[n-1],t;
a[0]=0;
a[1]=100;
s=0;
for(i=0; i<n; i++)
{
scanf("%lf",&a[i]);
if(a[0]<a[i])
{
t=a[0];
a[0]=a[i];
a[i]=t;
}
}
for(i=1; i<n; i++)
{
if(a[1]>a[i])
{
t=a[1];
a[1]=a[i];
a[i]=t;
}
}
getchar();
for(i=2; i<n; i++)
{
s=s+a[i];
}
printf("%.2lf\n",s/(n-2));
}
return 0;
}
未经精简,仅供参考。