wordpress搜索收录/外贸建站优化
大奖赛现场统分。已知某大奖赛有n个选手参赛,m(m>2)个评委为参赛选手评分(最高10分,最低0分)。统分规则为:在每个选手的m个得分中,去掉一个最高分和一个最低分后,取平均分作为该选手的最后得分。要求编程实现:
(1)根据n个选手的最后得分,从高到低输出选手的得分名次表,以确定获奖名单;
(2)根据各选手的最后得分与各评委给该选手所评分数的差距,对每个评委评分的准确性和评分水准给出一个定量的评价,每位评委的评分方法:(10 -(评委对选手x的评分 - x的得分)^2 的累加和),从高到低输出各评委得分的名次表。
程序运行示例如下:
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 <stdio.h>
#include <math.h>
#define ATHLETE 40 /* 选手人数最高限 */
#define JUDGE 20 /* 评委人数最高限 */
void CountAthleteScore(int sh[], float sf[], int n, float f[], 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[],int n);
int main()
{ int j, m, n;int sh[ATHLETE]; /* 选手的编号 */int ph[JUDGE]; /* 评委的编号 */float sf[ATHLETE]; /* 选手的最后得分 */float pf[JUDGE]; /* 评委的得分 */float f[ATHLETE][JUDGE]; /* 评委给选手的评分 */printf("How many Athletes?");scanf("%d", &n); /* 输入选手人数 */printf("How many judges?");scanf("%d", &m); /* 输入评委人数 */for (j = 1; j <= m; j++){ ph[j] = j;}printf("Scores of Athletes:\n");CountAthleteScore(sh, sf, n, *f, m); /* 现场为选手统计分数 */CountJudgeScore(ph, pf, m, sf, *f, n); /* 为各个评委打分 */printf("Order of Athletes:\n");Sort(sh, sf, n); /* 选手得分排序 */Print(sh, sf, n); /* 打印选手名次表 */printf("Order of judges:\n");Sort(ph, pf, m); /* 评委得分排序 */Print(ph, pf, m); /* 打印评委名次表 */printf("Over!Thank you!\n");return 0;
}
/* 函数功能:统计参赛选手的得分 */
void CountAthleteScore(int sh[], float sf[], int n, float f[], int m)
{ int i, j;float max, min;for (i = 1; i <= n; i++) /* 第i个选手 */{ printf("\nAthlete %d is playing.", i);printf("\nPlease enter his number code:");scanf("%d", &sh[i]);sf[i] = 0;max = 0; /* 最高分初值设为最小值 */min = 100; /* 最低分初值设为最大值 */for (j = 1; j <= m; j++) /* 第j个评委 */{ printf("Judge %d gives score:", j);scanf("%f", &f[i * m + j]);sf[i] = sf[i] + f[i * m + j]; /* 累加评委对第i个选手的评分 */if (max < f[i * m + j]) /* 找出最高分 */{ max = f[i * m + j];}if (min > f[i * m + j]) /* 找出最低分 */{ min = f[i * m + j];}}printf("Delete a maximum score:%.1f\n", max);printf("Delete a minimum score:%.1f\n", min);sf[i] = (sf[i] - max - min) / (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, k, temp2;float temp1;for (i = 1; i <= n - 1; i++){ k = i;for (j = i + 1; j <= n; j++){ if (f[j] > f[k]) k = j;}if (k != i){ temp1 = f[k];f[k] = f[i];f[i] = temp1;temp2 = h[k];h[k] = h[i];h[i] = temp2;}}
}
/* 函数功能:打印名次表 */
void Print(int h[], float f[], int n)
{ int i;printf("order\tfinal score\tnumber code\n");for (i = 1; i <= n; i++){ 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)
{ int i, j;for (j = 1; j <= m; j++) /* 第j个评委 */{ pf[j] = 0;for (i = 1; i <= n; i++) /* 第i个选手 */{ pf[j] = pf[j] + (f[i * m + j] - sf[i]) * (f[i * m + j] - sf[i]);}pf[j] = 10 - pf[j];}
}
当初没学这么多的时候,我甚至想直接硬破解
思路:
清晰的头脑,逻辑顺序,写的格式!!