某大奖赛有n个选手参赛,m个评委为依次参赛的选手评判打分
题目描述
某大奖赛有n(1<n<40)个选手参赛,m(2<m<20)个评委为依次参赛的选手评判打分:最高10分,最低0分。统分规则为:每个选手所得的m个得分中,去掉一个最高分,去掉一个最低分,最后平均为该选手的最后得分。根据n个选手的最后得分从高到低排出名次表,以便确定获奖名单。
输入
输入选手的数目n(1<n<40),评委的数目m(2<m<20),以及评委对每位选手的打分。
输出
选手的排名及最终的得分值(小数点后保留两位)。
样例输入
3,5
5.6 7.8 9.4 5.8 8.8
7.8 6.7 8.3 6.9 5.5
6.7 9.2 8.8 8.3 9.0
样例输出
第1名:3号选手,得分8.70
第2名:1号选手,得分7.47
第3名:2号选手,得分7.13提示
1.在输入样例中,第一行的"3,5”表示3个选手,5个评委。
2.在输入样例中,第二行为5个评委对第1位选手的分别打分;第三行为5个评委对第2位选手的分别打分;第四行为5个评委对第3位选手的分别打分.
3.在输出样例中出现的标点符号均在英文状态下输入的。 */
#include <stdio.h> void swap(float *, float *); float average(int m, float judge[]); void bubble_sort(int n, float competitor[]); int main() { int n, m; int max ; float judge[20]; float competitor[40]; float copycompetior[40]; int numberOfcompetitor[40];//储存选手编号 scanf("%d%d", &n, &m);//届时注意输入分隔符, for (int i = 0; i < n; i++) { competitor[i] = average(m, judge); // printf("%d\n",competitor[// printf(“%d \ n”,competitor [i]);i]); } for (int i = 0; i < n; i++) { copycompetior[i] = competitor[i]; } for (int i = 0; i < n ; i++) { //找到该趟次中最大元素所在位置索引. max = 0; for (int j = 1; j < n ; j++) { if (copycompetior[max] < copycompetior[j]) max = j ;//再打各补丁? } numberOfcompetitor[i] = max;//记录位置 copycompetior[max] = 0;//使之不会影响下一个排名的选手的查找. } bubble_sort(n, competitor); for (int i = 0; i < n; i++) { printf("第%d名: %d 号选手 得分%.2f分\n", i+1, numberOfcompetitor[i]+1, competitor[i]);//printf("%f(修改时若忽视将导致输出异常") } return 0;//主函数. } // void swap(float *a, float *b) { float temp; temp = *a; *a = *b; *b = temp; return;//修改旧变量(这一操作),二不带回其他值. } float average(int m, float judge[]) { float min, max, temp, sum = 0; scanf("%f", &judge[0]);//(也可以整合到for里面去),则min = max =judge[0]//初始化为0 min = max = judge[0]; //这是就要及时地为sum赋上第一个值(judge[0]),否则第一个值将丢失. sum = judge[0]; for (int i = 1; i < m; i++) { //不对数组进行任何排序性修改,只是记录最值,并保存(迭代更换)到指定的变量里 scanf("%f", &judge[i]);//函数内部的变量类型也要在修改函数是注意 sum += judge[i]; if (min > judge[i]) { //也可以使用swap() temp = judge[i]; judge[i] = min; min = temp; } else if (max < judge[i]) { temp = judge[i]; judge[i] = max; max = temp; } } sum = sum - min - max; return sum / (m - 2.0); } //循环:loop void bubble_sort(int n, float competitor[]) { int max; //事实上,选择排序法更适合于本题 for (int i = 0; i < n - 1; i++) {//i = 0的版本. //j作箭头指着.(从最后一个索引(n-1)) for (int j = n - 1; j > i; j--) {// j: 0,1,..., i,...n-2, n-1.(也可写作j<= n-2),该轮进行了n-2 - i + 1 = n-1-i次比较. max = n;//? //每一趟地最后一个元素由判断语句中的competitor[j+1]引入比较. if (competitor[j] > competitor[j - 1]) { swap(&competitor[j], &competitor[j - 1]); } }//该趟(对应行的排序结束) } return; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2022-09-17 队列:循环队列和双端队列/受限双端队列
2021-09-17 embedded_ssd 1306 OLED (黑白Monochrome 7-pin)(128x64)引脚解释+ssd1306 OLED的Fritzing元件模块(fzpz)文件
2021-09-17 picGo@图床配置@分支设置(避坑)