第十二周练兵区——编程题——不计入总分

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]是正常的,也是允许的。但如果某个评委给每个选手的评分与各选手的最后得分都相差太大,则说明该评委的评分有失水准。可用下面的公式来对各个评委的评分水平进行定量评价:

在这里插入图片描述

程序的运行结果示例:

How many Athletes?

3↙

How many judges?

4↙

Scores of Athletes:

Athlete 1 is playing.

Please enter his number code:

101↙

Judge 1 gives score:

9.8↙

Judge 2 gives score:

9.7↙

Judge 3 gives score:

9.5↙

Judge 4 gives score:

9.1↙

Delete a maximum score:9.8

Delete a minimum score:9.1

The final score of Athlete 101 is 9.600

Athlete 2 is playing.

Please enter his number code:

102↙

Judge 1 gives score:

8.9↙

Judge 2 gives score:

8.1↙

Judge 3 gives score:

8.6↙

Judge 4 gives score:

8.4↙

Delete a maximum score:8.9

Delete a minimum score:8.1

The final score of Athlete 102 is 8.500

Athlete 3 is playing.

Please enter his number code:

103↙

Judge 1 gives score:

9.0↙

Judge 2 gives score:

9.5↙

Judge 3 gives score:

9.4↙

Judge 4 gives score:

9.2↙

Delete a maximum score:9.5

Delete a minimum score:9.0

The final score of Athlete 103 is 9.300

Order of Athletes:

order final score number code

1          9.600       101

2          9.300       103

3          8.500       102

Order of judges:

order final score number code

1          9.900         3

2          9.735         2

3          9.700         4

4          9.689         1

Over!Thank you!

程序中浮点数的数据类型均为float。

输入选手人数提示信息:“How many Athletes?\n”

输入评委人数提示信息:“How many judges?\n”

输入选手编号提示信息:“Please enter his number code:\n”

输入格式:

评委人数、选手人数、选手编号:"%d"

评委打分:"%f"

输出格式:

选手得分提示信息:“Scores of Athletes:\n”

当前选手提示信息:“Athlete %d is playing.\n”

评委打分提示信息:“Judge %d gives score:\n”

去掉最高分:“Delete a maximum score:%.1f\n”

去掉最低分:“Delete a minimum score:%.1f\n”

选手最后得分提示信息:“The final score of Athlete %d is %.3f\n”

选手得分排序提示信息:“Order of Athletes:\n”

评委排序提示信息:“Order of judges:\n”

选手/评委 排序表头提示信息都是:“order\tfinal score\tnumber code\n”

选手/评委 得分排序输出格式都是:"%5d\t%11.3f\t%6d\n"

评委排序表头提示信息: “order\tfinal score\tnumber code\n”

评分结束提示信息: “Over!Thank you!\n”

#include <stdio.h>
#include <string.h>
#include <math.h>
#define N 10
float De_Max(float f[N][N], int i, int n);
float De_Min(float f[N][N], int i, int n);
void Calculate(float f[N][N], float sf[N], int sh[N], int m, int i, int n);
void Athlete_Output(float sf[N], int sh[N], int m, int n);
void Judge_Output(float f[N][N], float sf[N], float pf[N], int ph[N], int m, int n);
int main()
{
	int sh[N], ph[N];
	float f[N][N], sf[N], pf[N], copy1[N][N], copy2[N];
	int n, m, i, r;
	memset(sf, 0, sizeof(sf));
	printf("How many Athletes?\n");
	scanf("%d", &m);
	printf("How many judges?\n");
	scanf("%d", &n);
	printf("Scores of Athletes:\n");
	for(i=0;i<n;i++)
	{
		ph[i] = i+1;
	}
	for(i=0;i<m;i++)
	{
		printf("Athlete %d is playing.\n", i+1);
		printf("Please enter his number code:\n");
		scanf("%d", &sh[i]);
		for(r=0;r<n;r++)
		{
			printf("Judge %d gives score:\n", r+1);
			scanf("%f", &f[i][r]);
			sf[i] = sf[i] + f[i][r];
		}
		printf("Delete a maximum score:%.1f\n", De_Max(f, i, n));
		printf("Delete a minimum score:%.1f\n", De_Min(f, i, n));
		Calculate(f, sf, sh, m, i, n);
	}
	for(i=0;i<m;i++)
	{
		for(r=0;r<n;r++)
		{
			copy1[i][r] = f[i][r];
		}
	}
	for(i=0;i<m;i++)
	{
		copy2[i] = sf[i];
	}
	Athlete_Output(sf, sh, m, n);
	Judge_Output(copy1, copy2, pf, ph, m, n);
	printf("Over!Thank you!\n");
	return 0;
}
float De_Max(float f[N][N], int i, int n)
{
	float max=f[i][0];
	int r;
	for(r=0;r<n;r++)
	{
		if(max < f[i][r])
		{
			max = f[i][r];
		}
	}
	return max;
}
float De_Min(float f[N][N], int i, int n)
{
	float min=f[i][0];
	int r;
	for(r=0;r<n;r++)
	{
		if(min > f[i][r])
		{
			min = f[i][r];
		}
	}
	return min;
}
void Calculate(float f[N][N], float sf[N], int sh[N], int m, int i, int n)
{
	sf[i] = (sf[i]-De_Max(f, i, n)-De_Min(f, i, n))/(n-2);
	printf("The final score of Athlete %d is %.3f\n", sh[i], sf[i]);
	return ;
}
void Athlete_Output(float sf[N], int sh[N], int m, int n)
{
	int i, term1;
	float term2;
	printf("Order of Athletes:\n");
	for(i=0;i<n-1;i++)
	{
		if(sf[i] < sf[i+1])
		{
			term2 = sf[i];
			sf[i] = sf[i+1];
			sf[i+1] = term2;
			term1 = sh[i];
			sh[i] = sh[i+1];
			sh[i+1] = term1;
		}
	}
	printf("order\tfinal score\tnumber code\n");
	for(i=0;i<m;i++)
	{
		printf("%5d\t%11.3f\t%6d\n", i+1, sf[i], sh[i]);
	}
	return ;
}
void Judge_Output(float f[N][N], float sf[N], float pf[N], int ph[N], int n, int m)
{
	int i, r, term1;
	float sum, term2;
	printf("Order of judges:\n");
	printf("order\tfinal score\tnumber code\n");
	for(i=0;i<m;i++)
	{
		sum = 0;
		for(r=0;r<n;r++)
		{
			sum = sum + (f[r][i]-sf[r])*(f[r][i]-sf[r]);
		}
		sum = sum / (float)n;
		pf[i] = 10 - sqrt(sum);
	}
	for(r=0;r<n;r++)
	{
		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;
			}
		}
	}
	for(i=0;i<m;i++)
	{
		printf("%5d\t%11.3f\t%6d\n", i+1, pf[i], ph[i]);
	}
	return ;
}

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

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

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

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

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

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

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

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

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

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

(9)按优秀(90100)、良好(8089)、中等(7079)、及格(6069)、不及格(0~59)5个类别,统计每个类别的人数以及所占的百分比;

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

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

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please enter your choice:

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

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

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

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

int 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) ;

程序运行结果示例:

Input student number(n<30):

6↙

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

1↙

Input student’s ID, name and score:

11003001↙

lisi↙

87↙

11003005↙

heli↙

98↙

11003003↙

ludi↙

75↙

11003002↙

dumo↙

48↙

11003004↙

zuma↙

65↙

11003006↙

suyu↙

100↙

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

2↙

sum=473,aver=78.83

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

3↙

Sort in descending order by score:

11003006 suyu 100

11003005 heli 98

11003001 lisi 87

11003003 ludi 75

11003004 zuma 65

11003002 dumo 48

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

4↙

Sort in ascending order by score:

11003002 dumo 48

11003004 zuma 65

11003003 ludi 75

11003001 lisi 87

11003005 heli 98

11003006 suyu 100

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

5↙

Sort in ascending order by number:

11003001 lisi 87

11003002 dumo 48

11003003 ludi 75

11003004 zuma 65

11003005 heli 98

11003006 suyu 100

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

6↙

Sort in dictionary order by name:

11003002 dumo 48

11003005 heli 98

11003001 lisi 87

11003003 ludi 75

11003006 suyu 100

11003004 zuma 65

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

7↙

Input the number you want to search:

11003004↙

11003004 zuma 65

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

8↙

Input the name you want to search:

heli↙

11003005 heli 98

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

9↙

<60 1 16.67%

60-69 1 16.67%

70-79 1 16.67%

80-89 1 16.67%

90-99 1 16.67%

100 1 16.67%

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

10↙

11003002 dumo 48

11003005 heli 98

11003001 lisi 87

11003003 ludi 75

11003006 suyu 100

11003004 zuma 65

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

11↙

Input error!

Management for Students’ scores

1.Input record

2.Caculate total and average score of course

3.Sort in descending order by score

4.Sort in ascending order by score

5.Sort in ascending order by number

6.Sort in dictionary order by name

7.Search by number

8.Search by name

9.Statistic analysis

10.List record

0.Exit

Please Input your choice:

0↙

End of program!

输入格式:

( 1 ) 录入学生的人数:

             **要求输入数据格式为:"%d"

             **提示信息为:"Input student number(n<30):\n"

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

           **要求输入数据格式为:"%ld%s%f"

           **提示信息为:"Input student's ID, name and score:\n"

输出格式:

计算课程的总分和平均分:

          **要求输出总分与平均分格式为:"sum=%.0f,aver=%.2f\n"

按成绩由高到低排出名次表:

          **要求输出格式为:"%ld\t%s\t%.0f\n"

          **提示信息为:"Sort in descending order by score:\n"

按成绩由低到高排出名次表:

          **要求输出格式为:"%ld\t%s\t%.0f\n"

          **提示信息为:"Sort in ascending order by score:\n"

按学号由小到大排出成绩表:

          **要求输出格式为:"%ld\t%s\t%.0f\n"

          **提示信息为:"Sort in ascending order by number:\n"

按姓名的字典顺序排出成绩表

          **要求输出格式为:"%ld\t%s\t%.0f\n"

          **提示信息为:"Sort in dictionary order by name:\n"

按学号查询学生排名及其考试成绩:

           **如果未查到此学号的学生,提示信息为:"Not found!\n";

           **如果查询到该学生,要求输出格式为:"%ld\t%s\t%.0f\n"

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

           **如果未查到此学号的学生,提示信息为:"Not found!\n";

           **如果查询到该学生,要求输出格式为:"%ld\t%s\t%.0f\n"

按优秀(90100)、良好(8089)、中等(7079)、及格(6069)、不及格(0~59)5个类别,统计每个类别的人数以及所占的百分比:

            **成绩<60输出提示格式为:"<60\t%d\t%.2f%%\n";

            **成绩=100输出格式为:"%d\t%d\t%.2f%%\n";

            **其他要求输出百分比格式为:"%d-%d\t%d\t%.2f%%\n" 

输出每个学生的学号、姓名、考试成绩,以及课程总分和平均分

            **输出格式为:"%ld\t%s\t%.0f\n"

选择退出(菜单项0)

            **提示信息:"End of program!"

菜单项选择错误(不在0-10之间)

            **提示信息:"Input error!\n"
#include <stdio.h>
#include <string.h>
#define   MAX_LEN  10        	/* 字符串最大长度 */
#define   STU_NUM 30         /* 最多的学生人数 */
int   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()
{
	long num[STU_NUM];
	char name[STU_NUM][MAX_LEN];
	float score[STU_NUM];
	int n, m;
	printf("Input student number(n<30):\n");
	scanf("%d", &n);
	Menu();
	while(scanf("%d", &m) && m!=0)
	{
		switch(m)
		{
		case 1:printf("Input student's ID, name and score:\n");
			ReadScore(num, name, score, n);
			break;
		case 2:AverSumofScore(score, n);
			break;
		case 3:printf("Sort in descending order by score:\n");
			SortbyScore(num, name, score, n, Descending);
			break;
		case 4:printf("Sort in ascending order by score:\n");
			SortbyScore(num, name, score, n, Ascending);
			break;
		case 5:printf("Sort in ascending order by number:\n");
			AsSortbyNum(num, name, score, n);
			break;
		case 6:printf("Sort in dictionary order by name:\n");
			SortbyName(num, name, score, n);
			break;
		case 7:printf("Input the number you want to search:\n");
			SearchbyNum(num, name, score, n);
			break;
		case 8:printf("Input the name you want to search:\n");
			SearchbyName(num, name, score, n);
			break;
		case 9:StatisticAnalysis(score, n);
			break;
		case 10:PrintScore(num, name, score, n);
			break;
		default:printf("Input error!\n");
		}
		Menu();
	}
	printf("End of program!");
	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)
{
	int i;
	for(i=0;i<n;i++)
	{
		scanf("%ld%s%f", &num[i], &name[i], &score[i]);
	}
	return ;
}
void  AverSumofScore(float score[], int n)
{
	int i;
	float aver,sum=0;
	for(i=0;i<n;i++)
	{
		sum = sum + score[i];
	}
	aver = sum / (float)n;
	printf("sum=%.0f,aver=%.2f\n", sum, aver);
	return ;
}
void  SwapFloat(float *x, float *y)
{
	float term;
	term = *x;
	*x = *y;
	*y = term;
	return ;
}
void  SwapLong(long *x, long *y)
{
	long term;
	term = *x;
	*x = *y;
	*y = term;
	return ;
}
void  SwapChar(char x[], char y[])
{
	char term[MAX_LEN];
	strcpy(term, x);
	strcpy(x, y);
	strcpy(y, term);
	return ;
}
int   Ascending(float a, float b)
{
	if(a > b)
		return 1;
	return 0;
}
int   Descending(float a, float b)
{
	if(a < b)
		return 1;
	return 0;
}
void  SortbyScore(long num[], char name[][MAX_LEN], float score[], int n,int (*compare)(float a, float b))
{
	int i, r;
	for(i=0;i<n;i++)
	{
		for(r=0;r<n-1;r++)
		{
			if((*compare)(score[r], score[r+1]))
			{
				SwapFloat(&score[r], &score[r+1]);
				SwapLong(&num[r], &num[r+1]);
				SwapChar(name[r], name[r+1]);
			}
		}
	}
	for(i=0;i<n;i++)
	{
		printf("%ld\t%s\t%.0f\n", num[i], name[i], score[i]);
	}
	return ;
}
void  AsSortbyNum(long num[], char name[][MAX_LEN], float score[], int n)
{
	int i, r;
	for(i=0;i<n;i++)
	{
		for(r=0;r<n-1;r++)
		{
			if(num[r] > num[r+1])
			{
				SwapFloat(&score[r], &score[r+1]);
				SwapLong(&num[r], &num[r+1]);
				SwapChar(name[r], name[r+1]);
			}
		}
	}
	for(i=0;i<n;i++)
	{
		printf("%ld\t%s\t%.0f\n", num[i], name[i], score[i]);
	}
	return ;
}
void  SortbyName(long num[], char name[][MAX_LEN], float score[], int n)
{
	int i, r;
	for(i=0;i<n;i++)
	{
		for(r=0;r<n-1;r++)
		{
			if(strcmp(name[r], name[r+1]) > 0)
			{
				SwapFloat(&score[r], &score[r+1]);
				SwapLong(&num[r], &num[r+1]);
				SwapChar(name[r], name[r+1]);
			}
		}
	}
	for(i=0;i<n;i++)
	{
		printf("%ld\t%s\t%.0f\n", num[i], name[i], score[i]);
	}
	return ;
}
void  SearchbyNum(long num[], char name[][MAX_LEN], float score[], int n)
{
	int i;
	long c;
	scanf("%ld", &c);
	for(i=0;i<n;i++)
	{
		if(c%1000 == num[i]%1000)
		{
			printf("%ld\t%s\t%.0f\n", num[i], name[i], score[i]);
			return ;
		}
	}
	printf("Not found!\n");
	return ;
}
void  SearchbyName(long num[], char name[][MAX_LEN], float score[], int n)
{
	int i, lenth;
	char str[MAX_LEN];
	getchar();
	scanf("%s", str);
	lenth = strlen(str);
	for(i=0;i<lenth;i++)
	{
		if(strcmp(str, name[i]) == 0)
		{
			printf("%ld\t%s\t%.0f\n", num[i], name[i], score[i]);
			return ;
		}
	}
	printf("Not found!\n");
	return ;
}
void  StatisticAnalysis(float score[], int n)
{
	int i;
	int x[6];
	memset(x, 0, sizeof(x));
	for(i=0;i<n;i++)
	{
		if(score[i]<60)
			x[0]++;
		else if(score[i]<70)
			x[1]++;
		else if(score[i]<80)
			x[2]++;
		else if(score[i]<90)
			x[3]++;
		else if(score[i]<100)
			x[4]++;
		else 
			x[5]++;
	}
	printf("<60\t%d\t%.2f%%\n", x[0], (float)x[0]*100/(float)n);
	printf("%d-%d\t%d\t%.2f%%\n", 60, 69, x[1], (float)x[1]*100/(float)n);
	printf("%d-%d\t%d\t%.2f%%\n", 70, 79, x[2], (float)x[2]*100/(float)n);
	printf("%d-%d\t%d\t%.2f%%\n", 80, 89, x[3], (float)x[3]*100/(float)n);
	printf("%d-%d\t%d\t%.2f%%\n", 90, 99, x[4], (float)x[4]*100/(float)n);
	printf("%d\t%d\t%.2f%%\n", 100, x[5], (float)x[5]*100/(float)n);
	return ;
}
void  PrintScore(long num[], char name[][MAX_LEN], float score[], int n)
{
	int i, r;
	for(i=0;i<n;i++)
	{
		for(r=0;r<n-1;r++)
		{
			if(strcmp(name[r], name[r+1]) > 0)
			{
				SwapFloat(&score[r], &score[r+1]);
				SwapLong(&num[r], &num[r+1]);
				SwapChar(name[r], name[r+1]);
			}
		}
	}
	for(i=0;i<n;i++)
	{
		printf("%ld\t%s\t%.0f\n", num[i], name[i], score[i]);
	}
	return ;
}

3单词接龙(4分)

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

程序运行结果示例1:

happy↙

pythen↙

py

程序运行结果示例2:

sun↙

unknown↙

un

输入格式: “%s%s”

输出格式: “%s\n”

#include <stdio.h>
#include <string.h>
#define N 20
int main()
{
	char str1[N], str2[N], str3[N];
	int i, r=0, lenth1, lenth2;
	scanf("%s%s", str1, str2);
	lenth1 = strlen(str1);
	lenth2 = strlen(str2);
	for(i=0;i<lenth1;i++)
	{
		if(str1[i] == str2[0])
		{
			for(r=0;r<lenth2;r++)
			{
				if(str1[i+r] == str2[r])
				{
					str3[r] = str2[r];
				}
				else if(str1[i+r] != '\0')
				{
					break;
				}
				else
				{
					str3[r] = '\0';
				}
			}
		}
	}
	printf("%s\n", str3);
	return 0;
}

4分数比较(4分)

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

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

程序运行结果示例1:

Input two FENSHU:

17/19,23/27↙

17/19>23/27

程序运行结果示例2:

Input two FENSHU

2/3,2/3↙

2/3=2/3

程序运行结果示例3:

Input two FENSHU:

1/7,1/2↙

1/7<1/2

输入提示信息:“Input two FENSHU:\n”

输入格式: “%d/%d,%d/%d”

输出格式:

如果前者大于后者输出提示信息:"%d/%d>%d/%d\n"

如果前者等于后者输出提示信息:"%d/%d=%d/%d\n"

如果前者小于后者输出提示信息:"%d/%d<%d/%d\n"

#include<stdio.h>
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);
if(a*d==b*c)
printf("%d/%d=%d/%d\n",a,b,c,d);
if(a*d<b*c)
printf("%d/%d<%d/%d\n",a,b,c,d);
return 0;
}

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

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

输入格式: 无

输出格式:

输出百万富翁给陌生人的钱: “to Stranger: %.2f yuan\n”

输出陌生人给百万富翁的钱: “to Richman: %.2f yuan\n”

#include<stdio.h>
#include<math.h>
main()
{
double a,b=0.01,sum=0.01;
int i;
a=100000*30;
for(i=1;i<30;i++){
b=2*b;
sum=sum+b;}
printf("to Stranger: %.2f yuan\n",sum);
printf("to Richman: %.2f yuan\n",a);
return 0;
}

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

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

程序运行结果示例:

Input a number:

1↙

Input a number:

3↙

Input a number:

4↙

Input a number:

2↙

Input a number:

-8↙

Input a number:

-9↙

Input a number:

0↙

sum=10,count=4

输入提示信息: “Input a number:\n”

输入格式: “%d”

输出格式: “sum=%d,count=%d\n”

#include<stdio.h>
main()
{
int n,i,sum=0,count=0;
do{
printf( "Input a number:\n");
scanf("%d",&n);
if(n>0)
{
sum+=n;
count++;}
if(n<0)
sum+=0;
}while(n!=0);
printf("sum=%d,count=%d\n",sum,count);
return 0;
}

7平方根表(4分)

输出100(n2<=100)以内整数的平方根表,n的值要求从键盘输入,并且满足n2<=100 (即n的平方值在100以内)。

程序运行结果示例:
在这里插入图片描述
输入提示:“Input n(n<=10):\n”

输入格式: “%d”

输出格式:

输出表头: “%7d”

输出每行的开头数字: “%d”

输出第m行n列中的值:"%7.3f"

#include <stdio.h>
#include <math.h>
int main()
{
	int n;
	double i, r; 
	printf("Input n(n<=10):\n");
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		printf("%7d", (int)i);
	}
	printf("\n");
	for(i=0;i<n;i++)
	{
		printf("%d", (int)i);
		for(r=0;r<n;r++)
		{
			printf("%7.3f", sqrt(i*10+r));
		}
		printf("\n");
	}
	return 0;
}

8最大公约数(4分)

按照如下函数原型编写子函数计算正整数a和b的所有公约数。第一次调用,返回最大公约数。以后只要再使用相同参数调用,每次返回下一个小一些的公约数。无公约数时,函数CommonFactors()返回-1,主函数中不输出任何信息。

函数原型: int CommonFactors(int a, int b)

程序运行结果示例1:

Input a and b:

100,50↙

Common factor 1 is 50

Common factor 2 is 25

Common factor 3 is 10

Common factor 4 is 5

Common factor 5 is 2

Common factor 6 is 1

程序运行结果示例2:

Input a and b:

7,-3↙

输入提示信息:“Input a and b:\n”

输入格式: “%d,%d”

输出格式: “Common factor %d is %d\n”

#include<stdio.h>
int CommonFactors(int a, int b)
{
int i,r=0;
if(a>0&&b>0){
for(i=a;i>0;i--){
if(a%i==0&&b%i==0){
r++;
printf("Common factor %d is %d\n",r,i);}
}
}
if(a<0||b<0)
return -1;
}
main()
{
int a,b;
printf("Input a and b:\n");
scanf("%d,%d",&a,&b);
CommonFactors(a,b);
return 0;
}

923根火柴游戏(4分)

请编写一个简单的23 根火柴游戏程序,实现人跟计算机玩这个游戏的程序。为了方便程序自动评测,假设计算机移动的火柴数不是随机的,而是将剩余的火柴根数对3求余后再加1来作为计算机每次取走的火柴数。如果剩余的火柴数小于3,则将剩余的火柴数减1作为计算机移走的火柴数。但是计算机不可以不取,剩下的火柴数为1时,必须取走1根火柴。假设游戏规则如下:

1)游戏者开始拥有23根火柴棒;

2)每个游戏者轮流移走1 根、2 根或3 根火柴;

3)谁取走最后一根火柴为失败者。

程序运行结果示例1:

Game start!

Note: the maximum number is 3

Please enter the number of matches you are moving:

5↙

The number you entered is wrong,please re-enter!

Please enter the number of matches you are moving:

3↙

The number of matches you are moving is:3

The number of matches left is:20

The number of matches that have been moved by the computer is:3

The number of matches left is:17

Please enter the number of matches you are moving:

1↙

The number of matches you are moving is:1

The number of matches left is:16

The number of matches that have been moved by the computer is:2

The number of matches left is:14

Please enter the number of matches you are moving:

2↙

The number of matches you are moving is:2

The number of matches left is:12

The number of matches that have been moved by the computer is:1

The number of matches left is:11

Please enter the number of matches you are moving:

3↙

The number of matches you are moving is:3

The number of matches left is:8

The number of matches that have been moved by the computer is:3

The number of matches left is:5

Please enter the number of matches you are moving:

1↙

The number of matches you are moving is:1

The number of matches left is:4

The number of matches that have been moved by the computer is:2

The number of matches left is:2

Please enter the number of matches you are moving:

1↙

The number of matches you are moving is:1

The number of matches left is:1

The number of matches that have been moved by the computer is:1

The number of matches left is:0

Congratulations!You won!

程序运行结果示例2:

Game start!

Note: the maximum number is 3

Please enter the number of matches you are moving:

3↙

The number of matches you are moving is:3

The number of matches left is:20

The number of matches that have been moved by the computer is:3

The number of matches left is:17

Please enter the number of matches you are moving:

3↙

The number of matches you are moving is:3

The number of matches left is:14

The number of matches that have been moved by the computer is:3

The number of matches left is:11

Please enter the number of matches you are moving:

2↙

The number of matches you are moving is:2

The number of matches left is:9

The number of matches that have been moved by the computer is:1

The number of matches left is:8

Please enter the number of matches you are moving:

1↙

The number of matches you are moving is:1

The number of matches left is:7

The number of matches that have been moved by the computer is:2

The number of matches left is:5

Please enter the number of matches you are moving:

3↙

The number of matches you are moving is:3

The number of matches left is:2

The number of matches that have been moved by the computer is:1

The number of matches left is:1

Please enter the number of matches you are moving:

1↙

The number of matches you are moving is:1

The number of matches left is:0

I’m sorry. You lost!

游戏开始提示信息:“Game start!\n”

             "Note: the maximum number is 3\n"

提示游戏者输入移动的火柴数:“Please enter the number of matches you are moving:\n”

游戏者输入错误数据的提示信息:“The number you entered is wrong,please re-enter!\n”

输入格式: “%d”

输出格式:

输出被游戏者移动的火柴数:"The number of matches you are moving is:%d\n"

输出被计算机移动的火柴数:"The number of matches that have been moved by the computer is:%d\n"

输出被游戏者或计算机移动后剩余的火柴数:"The number of matches left is:%d\n"

游戏者获胜的输出提示信息:“Congratulations!You won!\n”

游戏者失败的输出提示信息:“I’m sorry. You lost!\n”

#include <stdio.h>
int main()
{
	int sum=23, n, m;
	printf("Game start!\n");
	printf("Note: the maximum number is 3\n");
	printf("Please enter the number of matches you are moving:\n");
	while(scanf("%d", &n) != EOF)
	{
		if(n<0 || n>3)
		{
			printf("The number you entered is wrong,please re-enter!\n");
			printf("Please enter the number of matches you are moving:\n");
			continue;
		}
		else
		{
			printf("The number of matches you are moving is:%d\n", n);
			sum = sum - n;
			printf("The number of matches left is:%d\n", sum);
			if(sum == 0)
			{
				printf("I'm sorry. You lost!\n");
				break;
			}
			if(sum >= 3)
			{
				m = sum%3+1;
			}
			else if(sum > 1)
			{
				m = sum - 1;
			}
			else 
			{
				m = 1;
			}
			printf("The number of matches that have been moved by the computer is:%d\n", m);
			sum = sum - m;
			printf("The number of matches left is:%d\n", sum);
			if(sum == 0)
			{
				printf("Congratulations!You won!\n");
				break;
			}
			printf("Please enter the number of matches you are moving:\n");
		}
	}
	return 0;
}
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值