一维数组实验题:大奖赛现场统分。已知某大奖赛有n个选手参赛,m(m>2)个评委为参赛选手评分(最高10分,最低0分)。统分规则为:在每个选手的m个得分中,去掉一个最高分和一个最低分后,取平均分作为该选手的最后得分。要求编程实现:
(1)根据n个选手的最后得分,从高到低输出选手的得分名次表,以确定获奖名单;
(2)根据各选手的最后得分与各评委给该选手所评分数的差距,对每个评委评分的准确性和评分水准给出一个定量的评价,每位评委的评分方法:(10 -(评委对选手x的评分 - x的得分)^2 的累加和),从高到低输出各评委得分的名次表。
输入提示:
printf(“How many Athletes?”);
scanf("%d", &n); /* 输入选手人数 /
printf(“How many judges?”);
scanf("%d", &m); / 输入评委人数 */
printf("Order of Athletes:\n"); /* 选手得分排序 */
printf("Order of judges:\n"); /* 评委得分排序 */
/* 函数功能:统计参赛选手的得分 */
void CountAthleteScore(int sh[], float sf[], int n, float f[], int m)
printf("\nAthlete %d is playing.", i);
printf("\nPlease enter his number code:");
scanf("%d", &sh[i]);
for (j = 1; j <= m; j++) /* 第j个评委 */
{
printf(“Judge %d gives score:”, j);
printf("Delete a maximum score:%.1f\n", max);
printf("Delete a minimum score:%.1f\n", min); /*去掉一个最高分和最低分*/
/* 函数功能:对分数从高到低排序 */
void Sort(int h[], float f[], int n)
/* 函数功能:打印名次表 */
void Print(int h[], float f[], int n)
printf(“order\tfinal score\tnumber code\n”);
printf("%5d\t%11.3f\t%6d\n", i, f[i], h[i]);
/* 函数功能:统计评委的得分 */
void CountJudgeScore(int ph[], float pf[], int m, float sf[], float f[], int n)
程序运行示例如下:
How many Athletes?5
How many judges?5
Scores of Athletes:
Athlete 1 is playing.
Please enter his number code:11
Judge 1 gives score:9.5
Judge 2 gives score:9.6
Judge 3 gives score:9.7
Judge 4 gives score:9.4
Judge 5 gives score:9.0
Delete a maximum score:9.7
Delete a minimum score:9.0
The final score of Athlete 11 is 9.500
Athlete 2 is playing.
Please enter his number code:12
Judge 1 gives score:9.0
Judge 2 gives score:9.2
Judge 3 gives score:9.1
Judge 4 gives score:9.3
Judge 5 gives score:8.9
Delete a maximum score:9.3
Delete a minimum score:8.9
The final score of Athlete 12 is 9.100
Athlete 3 is playing.
Please enter his number code:13
Judge 1 gives score:9.6
Judge 2 gives score:9.7
Judge 3 gives score:9.5
Judge 4 gives score:9.8
Judge 5 gives score:9.4
Delete a maximum score:9.8
Delete a minimum score:9.4
The final score of Athlete 13 is 9.600
Athlete 4 is playing.
Please enter his number code:14
Judge 1 gives score:8.9
Judge 2 gives score:8.8
Judge 3 gives score:8.7
Judge 4 gives score:9.0
Judge 5 gives score:8.6
Delete a maximum score:9.0
Delete a minimum score:8.6
The final score of Athlete 14 is 8.800
Athlete 5 is playing.
Please enter his number code:15
Judge 1 gives score:9.0
Judge 2 gives score:9.1
Judge 3 gives score:8.8
Judge 4 gives score:8.9
Judge 5 gives score:9.2
Delete a maximum score:9.2
Delete a minimum score:8.8
The final score of Athlete 15 is 9.000
Order of Athletes:
order final score number code
1 9.600 13
2 9.500 11
3 9.100 12
4 9.000 15
5 8.800 14
Order of judges:
order final score number code
1 9.980 1
2 9.960 2
3 9.900 3
4 9.860 4
5 9.590 5
Over!Thank you!
#include
#include
void CountAthleteScore(int sh[], float sf[], int n, float f[][10], int m); /* 函数功能:统计参赛选手的得分 */
void Sort(int h[], float f[], int n); /* 函数功能:对分数从高到低排序 */
void Print(int h[], float f[], int n); /* 函数功能:打印名次表 */
void CountJudgeScore(int ph[], float pf[], int m, float sf[], float f[][10], int n); /* 函数功能:统计评委的得分 */
int main()
{
int n,m,sh[10],ph[10]; //sh[]选手编号,ph[]评委编号
float sf[10],f[10][10],pf[10]; //f[]每个评委给选手打分,sf[]每个选手最终得分,pf[]评委得分
printf("How many Athletes?");
scanf("%d", &n); /* 输入选手人数 */
printf("How many judges?");
scanf("%d", &m); /* 输入评委人数 */
printf("Scores of Athletes:\n");
CountAthleteScore(sh,sf,n,f,m);
CountJudgeScore(ph,pf,m,sf,f,n);
Sort(sh,sf,n); //选手成绩排序
printf("Order of Athletes:\n"); /* 选手得分排序 */
Print(sh,sf,n); //选手排名打印
printf("Order of judges:\n"); /* 评委得分排序 */
Sort(ph,pf,m);
Print(ph,pf,m);
printf("Over!Thank you!");
return 0;
}
void CountAthleteScore(int sh[], float sf[], int n, float f[][10], int m)
{
int i,j,k,g,t,w,e;
float s,max,min;
for(i=0;i<n;i++)
{
printf("\nAthlete %d is playing.", i+1);
printf("\nPlease enter his number code:");
scanf("%d", &sh[i]);
for (j = 0; j < m; j++) //录入成绩
{
printf("Judge %d gives score:", j+1);
scanf("%f",&f[i][j]);
getchar();
}
max=f[i][0];
w=0;
for(g=1;g<m;g++)
{
if(max<f[i][g])
{
max=f[i][g];
w=g;//记录最高分标号
}
}
min=f[i][0];
e=0;
for(t=1;t<m;t++)
{
if(min>f[i][t])
{
min=f[i][t];
e=t;//记录最低分标号
}
}
printf("Delete a maximum score:%.1f\n", max);
printf("Delete a minimum score:%.1f\n", min); /*去掉一个最高分和最低分*/
s=0;
for(k=0;k<m;k++) //计算最终得分
{
if(k!=w&&k!=e)
s+=f[i][k];
}
sf[i]=s/(m-2);
printf("The final score of Athlete %d is %.3f\n",sh[i],sf[i]);
}
}
void Sort(int h[], float f[], int n)
{
int i,j;
float t;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(f[i]<f[j])
{
t=f[i];
f[i]=f[j]; //交换成绩
f[j]=t;
t=h[i];
h[i]=h[j]; //交换编号
h[j]=t;
}
}
}
}
void Print(int h[], float f[], int n)
{
int i;
printf("order\tfinal score\tnumber code\n");
for(i=0;i<n;i++)
{
printf("%5d\t%11.3f\t%6d\n", i+1, f[i], h[i]);
}
}
void CountJudgeScore(int ph[], float pf[], int m, float sf[], float f[][10], int n)
{
int i,j;
float s,t;
for(i=0;i<m;i++)
{
s=0;
for(j=0;j<n;j++)
{
t=(f[j][i]-sf[j])*(f[j][i]-sf[j]);
s+=t;
}
pf[i]=10-s;
ph[i]=i+1;
}
}