首页 >> 大全

MOOC哈工大2020C语言程序设计精髓练兵区编程题第十二周

2023-12-21 大全 27 作者:考证青年

1 大奖赛现场统分(4分)

题目内容:

已知某大奖赛有n个选手参赛,m(m>2)个评委为参赛选手评分(最高10分,最低0分)。统分规则为:在每个选手的m个得分中,去掉一个最高分和一个最低分后,取平均分作为该选手的最后得分。要求编程实现:

(1)根据n个选手的最后得分,从高到低输出选手的得分名次表,以确定获奖名单;

(2)根据各选手的最后得分与各评委给该选手所评分数的差距,对每个评委评分的准确性和评分水准给出一个定量的评价,从高到低输出各评委得分的名次表。

提示:首先设计如下5个数组:

(1)sh[i],存放第i个选手的编号;

(2)sf[i],存放第i个选手的最后得分,即去掉一个最高分和一个最低分以后的平均分;

(3)ph[j],存放第j个评委的编号;

(4)f[i][j],存放第j个评委给第i个选手的评分;

(5)pf[j],存放代表第j个评委评分水准的得分。

解决本问题的关键在于计算选手的最后得分和评委的得分。

先计算选手的最后得分。外层循环控制参赛选手的编号i从1变化到n,当第i个选手上场时,输入该选手的编号sh[i]。内层循环控制给选手评分的评委的编号j从1变化到m,依次输入第j个评委给第i个选手的评分f[i][j],并将其累加到sf[i]中,同时求出最高分max和最低分min。当第i个选手的m个得分全部输入并累加完毕后,去掉一个最高分max,去掉一个最低分min,于是第i个选手的最后得分为:

sf[i] = (sf[i] – max – min)/(m-2);

当n个参赛选手的最后得分sf[0],sf[1],…,sf[n]全部计算完毕后,再将其从高到低排序,打印参赛选手的名次表。

下面计算评委的得分。评委给选手评分存在误差,即f[i][j]≠sf[i]是正常的,也是允许的。但如果某个评委给每个选手的评分与各选手的最后得分都相差太大,则说明该评委的评分有失水准。可用下面的公式来对各个评委的评分水平进行定量评价:

#define N 10//找最大值,返回索引
int FindMax(float scores[], int n);//找最小值,返回索引
int FindMin(float scores[], int n);//计算最终分数
float CalculationFinalScore(float scores[], int n, int maxIndex, int minIndex);//选手排序
void OrderAthletes(float sf[], int sh[], int n);//评委排序
void OrderJudges(float f[][N], float sf[], float pf[], int ph[], int n, int m);int main()
{int n, m, maxIndex, minIndex, sh[N], ph[N];float aver, scores[N], sf[N], pf[N], f[N][N], avers[N];printf("How many Athletes?\n");scanf("%d", &n);printf("How many judges?\n");scanf("%d", &m);printf("Scores of Athletes:\n");for (int k = 0; k < m; ++k){ph[k] = k + 1;}//多少位选手for (int i = 0; i < n; i++){printf("Athlete %d is playing.\n", i + 1);printf("Please enter his number code:\n");scanf("%d", &sh[i]);//评委for (int j = 0; j < m; ++j){printf("Judge %d gives score:\n", j + 1);scanf("%f", &f[i][j]);scores[j] = f[i][j];}maxIndex = FindMax(scores, m);minIndex = FindMin(scores, m);printf("Delete a maximum score:%.1f\n", scores[maxIndex]);printf("Delete a minimum score:%.1f\n", scores[minIndex]);aver = CalculationFinalScore(scores, m, maxIndex, minIndex);printf("The final score of Athlete %d is %.3f\n", sh[i], aver);//平均分放进数组sf[i] = aver;avers[i] = aver;}printf("Order of Athletes:\n");OrderAthletes(sf, sh, n);printf("Order of judges:\n");OrderJudges(f, avers, pf, ph, n, m);printf("Over!Thank you!\n");
}int FindMax(float scores[], int n)
{int max = 0;for (int i = 1; i < n; ++i){if (scores[max] < scores[i]){max = i;}}return max;
}int FindMin(float scores[], int n)
{int min = 0;for (int i = 1; i < n; ++i){if (scores[min] > scores[i]){min = i;}}return min;
}float CalculationFinalScore(float scores[], int n, int maxIndex, int minIndex)
{float sum = 0;for (int i = 0; i < n; ++i){if (i == maxIndex || i == minIndex){continue;}sum += scores[i];}return sum / (n - 2);
}void OrderAthletes(float sf[], int sh[], int n)
{float temp;int flag, t;for (int i = 0; i < n; ++i){flag = 0;for (int j = 0; j < n - i - 1; ++j){if (sf[j] < sf[j + 1]){temp = sf[j + 1];sf[j + 1] = sf[j];sf[j] = temp;t = sh[j + 1];sh[j + 1] = sh[j];sh[j] = t;flag = 1;}}if (!flag){break;}}printf("order\tfinal score\tnumber code\n");for (int k = 0; k < n; ++k){printf("%5d\t.3f\t%6d\n", k + 1, sf[k], sh[k]);}
}void OrderJudges(float f[][N], float sf[], float pf[], int ph[], int n, int m)
{int i, j, term1;float sum, term2;for (i = 0; i < m; i++){sum = 0;for (j = 0; j < n; j++){sum = sum + (f[j][i] - sf[j]) * (f[j][i] - sf[j]);}sum = sum / (float) n;pf[i] = 10 - sqrt(sum);}for (j = 0; j < n; j++){for (i = 0; i < m - 1; i++){if (pf[i] < pf[i + 1]){term1 = ph[i];ph[i] = ph[i + 1];ph[i + 1] = term1;term2 = pf[i];pf[i] = pf[i + 1];pf[i + 1] = term2;}}}printf("order\tfinal score\tnumber code\n");for (i = 0; i < m; i++){printf("%5d\t.3f\t%6d\n", i + 1, pf[i], ph[i]);}
}

2 学生成绩管理系统V3.0(4分)

题目内容:

某班有最多不超过30人(具体人数由键盘输入)参加某门课程的考试,参考第11周在线测验中“学生成绩管理系统V2.0”,用二维字符数组作函数参数编程实现如下菜单驱动的学生成绩管理系统:

(1)录入每个学生的学号、姓名和考试成绩;

(2)计算课程的总分和平均分;

(3)按成绩由高到低排出名次表;

(4)按成绩由低到高排出名次表;

(5)按学号由小到大排出成绩表;

(6)按姓名的字典顺序排出成绩表;

(7)按学号查询学生排名及其考试成绩;

(8)按姓名查询学生排名及其考试成绩;

(9)按优秀(90~100)、良好(80~89)、中等(70~79)、及格(60~69)、不及格(0~59)5个类别,统计每个类别的人数以及所占的百分比;

(10)输出每个学生的学号、姓名、考试成绩。

要求程序运行后先显示如下菜单,并提示用户输入选项:

1.Input

2. total and score of

3.Sort in order by score

4.Sort in order by score

5.Sort in order by

6.Sort in order by name

7. by

8. by name

9.

10.List

0.Exit

enter your :

然后,根据用户输入的选项执行相应的操作。

请按照下面的定义及函数原型编程

# 10 /* 字符串最大长度 */

# 30 /* 最多的学生人数 */

int Menu(void);

void (long num[], char name[][], float score[], int n);

void (float score[], int n);

void (long num[], char name[][], float score[], int n,

int (*)(float a, float b));

int (float a, float b);

int (float a, float b);

void (float *x, float *y);

_程序训练法有哪几种基本结构_编程语言进阶

void (long *x, long *y);

void (char x[], char y[]);

void (long num[], char name[][], float score[], int n);

void (long num[], char name[][], float score[], int n);

void (long num[], char name[][], float score[], int n);

void (long num[], char name[][], float score[], int n);

void (float score[], int n);

void (long num[], char name[][], float score[], int n) ;

#include 
// 字符串最大长度
#define   MAX_LEN  10
// 最多的学生人数
#define   STU_NUM 30int Menu(void);void ReadScore(long num[], char name[][MAX_LEN], float score[], int n);void AverSumofScore(float score[], int n);void SortbyScore(long num[], char name[][MAX_LEN], float score[], int n, int (*compare)(float a, float b));int Ascending(float a, float b);int Descending(float a, float b);void SwapFloat(float *x, float *y);void SwapLong(long *x, long *y);void SwapChar(char x[], char y[]);void AsSortbyNum(long num[], char name[][MAX_LEN], float score[], int n);void SortbyName(long num[], char name[][MAX_LEN], float score[], int n);void SearchbyNum(long num[], char name[][MAX_LEN], float score[], int n);void SearchbyName(long num[], char name[][MAX_LEN], float score[], int n);void StatisticAnalysis(float score[], int n);void PrintScore(long num[], char name[][MAX_LEN], float score[], int n);int main()
{int n, m;long num[STU_NUM];float scores[STU_NUM];char name[STU_NUM][MAX_LEN];printf("Input student number(n<30):\n");scanf("%d", &n);Menu();while (scanf("%d", &m) && m != 0){switch (m){case 1:ReadScore(num, name, scores, n);break;case 2:AverSumofScore(scores, n);break;case 3:printf("Sort in descending order by score:\n");SortbyScore(num, name, scores, n, Descending);break;case 4:printf("Sort in ascending order by score:\n");SortbyScore(num, name, scores, n, Ascending);break;case 5:printf("Sort in ascending order by number:\n");AsSortbyNum(num, name, scores, n);break;case 6:printf("Sort in dictionary order by name:\n");SortbyName(num, name, scores, n);break;case 7:SearchbyNum(num, name, scores, n);break;case 8:SearchbyName(num, name, scores, n);break;case 9:StatisticAnalysis(scores, n);break;case 10:PrintScore(num, name, scores, n);break;default:printf("Input error!\n");}Menu();}printf("End of program!\n");return 0;
}int Menu(void)
{printf("Management for Students' scores\n""1.Input record\n""2.Caculate total and average score of course\n""3.Sort in descending order by score\n""4.Sort in ascending order by score\n""5.Sort in ascending order by number\n""6.Sort in dictionary order by name\n""7.Search by number\n""8.Search by name\n""9.Statistic analysis\n""10.List record\n""0.Exit\n""Please Input your choice:\n");return 0;
}void ReadScore(long num[], char name[][MAX_LEN], float score[], int n)
{printf("Input student's ID, name and score:\n");for (int i = 0; i < n; ++i){scanf("%ld%s%f", &num[i], name[i], &score[i]);}
}void AverSumofScore(float score[], int n)
{float sum = 0;for (int i = 0; i < n; ++i){sum += score[i];}printf("sum=%.0f,aver=%.2f\n", sum, sum / n);
}void SortbyScore(long num[], char name[][MAX_LEN], float score[], int n, int (*compare)(float a, float b))
{int flag;for (int i = 0; i < n; ++i){flag = 0;for (int j = 0; j < n - i - 1; ++j){if((*compare)(score[j], score[j + 1])){SwapFloat(&score[j], &score[j + 1]);SwapLong(&num[j], &num[j + 1]);SwapChar(name[j], name[j + 1]);flag = 1;}}if(!flag){break;}}PrintScore(num, name, score, n);
}int  Ascending(float a, float b)
{return a > b ? 1 : 0;
}int Descending(float a, float b)
{return a < b ? 1 : 0;
}void SwapFloat(float *x, float *y)
{float temp;temp = *x;*x = *y;*y = temp;
}void SwapLong(long *x, long *y)
{long temp;temp = *x;*x = *y;*y = temp;
}void SwapChar(char x[], char y[])
{char temp[MAX_LEN];strcpy(temp, x);strcpy(x, y);strcpy(y, temp);
}void AsSortbyNum(long num[], char name[][MAX_LEN], float score[], int n)
{int flag;for (int i = 0; i < n; ++i){flag = 0;for (int j = 0; j < n - i - 1; ++j){if(num[j] > num[j + 1]){SwapLong(&num[j], &num[j + 1]);SwapFloat(&score[j], &score[j + 1]);SwapChar(name[j], name[j + 1]);flag = 1;}}if(!flag){break;}}PrintScore(num, name, score, n);
}void SortbyName(long num[], char name[][MAX_LEN], float score[], int n)
{int flag;for (int i = 0; i < n; ++i){flag = 0;for (int j = 0; j < n - i - 1; ++j){if(strcmp(name[j], name[j + 1]) > 0){SwapLong(&num[j], &num[j + 1]);SwapFloat(&score[j], &score[j + 1]);SwapChar(name[j], name[j + 1]);flag = 1;}}if(!flag){break;}}PrintScore(num, name, score, n);
}void SearchbyNum(long num[], char name[][MAX_LEN], float score[], int n)
{long number;int flag = 0, i;printf("Input the number you want to search:\n");scanf("%ld", &number);for (i = 0; i < n; ++i){if(number == num[i]){flag = 1;break;}}if(flag){printf("%ld\t%s\t%.0f\n", num[i], name[i], score[i]);}else{printf("Not found!\n");}}void SearchbyName(long num[], char name[][MAX_LEN], float score[], int n)
{char str[MAX_LEN];int i, flag = 0;printf("Input the name you want to search:\n");scanf("%s", str);for (i = 0; i < n; ++i){if(strcmp(name[i], str) == 0){flag = 1;break;}}if(flag){printf("%ld\t%s\t%.0f\n", num[i], name[i], score[i]);}else{printf("Not found!\n");}
}void StatisticAnalysis(float scores[], int n)
{int a, b, c, d, e, f;a = b = c = d = e = f = 0;float score;for (int i = 0; i < n; ++i){score = scores[i];if(score == 100){a++;}else if(score >= 90 && score < 100 ){b++;}else if(score >= 80){c++;}else if(score >= 70){d++;}else if(score >= 60){e++;}else{f++;}}printf("<60\t%d\t%.2f%%\n", f, (float)(100 * f) / n);printf("%d-%d\t%d\t%.2f%%\n" , 60, 69, e, (float)(100 * e) / n);printf("%d-%d\t%d\t%.2f%%\n" , 70, 79, d, (float)(100 * d) / n);printf("%d-%d\t%d\t%.2f%%\n" , 80, 89, c, (float)(100 * c) / n);printf("%d-%d\t%d\t%.2f%%\n" , 90, 99, b, (float)(100 * b) / n);printf("%d\t%d\t%.2f%%\n", 100, a,(float)(100 * a) / n);
}void PrintScore(long num[], char name[][MAX_LEN], float score[], int n)
{for (int k = 0; k < n; ++k){printf("%ld\t%s\t%.0f\n", num[k], name[k], score[k]);}
}

3 单词接龙(4分)

题目内容:

阿泰和女友小菲用英语短信玩单词接龙游戏。一人先写一个英文单词,然后另一个人回复一个英文单词,要求回复单词的开头有若干个字母和上一个人所写单词的结尾若干个字母相同,重合部分的长度不限。(如阿泰输入happy,小菲可以回复,重合部分为py。)现在,小菲刚刚回复了阿泰一个单词,阿泰想知道这个单词与自己发过去的单词的重合部分是什么。他们两人都是喜欢写长单词的英语大神,阿泰觉得用肉眼找重合部分实在是太难了,所以请你编写程序来帮他找出重合部分。

#define STR_LEN 80int main()
{char word[STR_LEN + 1], word2[STR_LEN + 1], word3[STR_LEN + 1];int i = 0, j = 0, k = 0;scanf("%s%s", word, word2);while (word[i] != '\0'){if(word[i] == word2[0]){while (word2[j] != '\0'){if(word[i + j] != word2[j]){break;}else{word3[k] = word2[j];k++;}j++;}word3[k] = '\0';}i++;}printf("%s\n", word3);return 0;
}

4 分数比较(4分)

题目内容:

比较两个分数的大小。人工方式下比较分数大小最常见的方法是:进行分数的通分后比较分子的大小。可以编程模拟手工解决。

具体要求为首先输出("Input two :\n"),然后输入两个分数分子分母的值,格式为("%d/%d,%d/%d"),判断完成后输出("%d/%d%d/%d\n")或("%d/%d=%d/%d\n");

int main()
{int a, b, c, d;printf("Input two FENSHU:\n");scanf("%d/%d,%d/%d", &a, &b, &c, &d);if(a * d > b * c){printf("%d/%d>%d/%d\n", a, b, c, d);}else if(a * d == b * c){printf("%d/%d=%d/%d\n", a, b, c, d);}else{printf("%d/%d<%d/%d\n", a, b, c, d);}return 0;
}

5 百万富翁的换钱计划(4分)

题目内容:

有一天,一位百万富翁遇到一个陌生人,陌生人找他谈一个换钱的计划,陌生人对百万富翁说:“我每天给你10万元,而你第一天只需给我1分钱,第二天我仍给你10万元,你给我2分钱,第三天我仍给你10万元,你给我4分钱……。你每天给我的钱是前一天的两倍,直到满一个月(30天)为止”,百万富翁很高兴,欣然接受了这个契约。请编程计算在这一个月中陌生人总计给百万富翁多少钱,百万富翁总计给陌生人多少钱。程序中浮点数的数据类型均为。

int main()
{double stranger = 0, richMan = 0;for (int i = 1; i <= 30; ++i){richMan += 100000;stranger += pow(2, i - 1) * 0.01;}printf("to Stranger: %.2f yuan\n", stranger);printf("to Richman: %.2f yuan\n", richMan);return 0;
}

6 用计数控制的循环实现正数累加求和(4分)

题目内容:

输入一些整数,编程计算并输出其中所有正数的和,输入负数时不累加,继续输入下一个数。输入零时,表示输入数据结束。要求最后统计出累加的项数。

int main()
{int count = 0, sum = 0, n;do{printf("Input a number:\n");scanf("%d", &n);if(n < 0){continue;}sum += n;count++;}while (n != 0);printf("sum=%d,count=%d\n", sum, count - 1);return 0;
}

7 平方根表(4分)

题目内容:

输出100(n^2

关于我们

最火推荐

小编推荐

联系我们


版权声明:本站内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 88@qq.com 举报,一经查实,本站将立刻删除。备案号:桂ICP备2021009421号
Powered By Z-BlogPHP.
复制成功
微信号:
我知道了