题目内容:
已知某大奖赛有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”
为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。
时间限制:500ms内存限制:32000kb
C
#include
#include
#include
#include
#define N 1000
float f[N][N];//f[i][j],存放第j个评委给第i个选手的评分;
typedef struct athlete{
int sh; //sh[i],存放第i个选手的编号;
float sf;//sf[i],存放第i个选手的最后得分,即去掉一个最高分和一个最低分以后的平均分;
} Athlete;
typedef struct judge{
int ph;//ph[j],存放第j个评委的编号;
float pf; //pf[j],存放代表第j个评委评分水准的得分。
} Judge;
Athlete a[N];
Judge b[N];
int cmpA(const void *a, const void *b){
Athlete *a1=(Athlete *)a;
Athlete *a2=(Athlete *)b;
if(a2->sf > a1->sf) return 1;
else return -1;
}
int cmpJ(const void *a, const void *b){
Judge *a1=(Judge *)a;
Judge *a2=(Judge *)b;
if(a2->pf > a1->pf) return 1;
else return -1;
}
int main()
{
// freopen("C:\\Users\\Ambition\\Desktop\\in.txt","r",stdin);
int n, m, i, j;
printf("How many Athletes?\n");
scanf("%d", &n);
printf("How many judges?\n");
scanf("%d", &m);
printf("Scores of Athletes:\n");
for(i=0; i<n; ++i){
float maxScore=0, minScore=10, sum=0;
printf("Athlete %d is playing.\n", i+1);
printf("Please enter his number code:\n");
scanf("%d", &a[i].sh);
for(j=0; j<m; ++j){
printf("Judge %d gives score:\n", j+1);
scanf("%f", &f[i][j]);
sum+=f[i][j];
if(f[i][j]>maxScore) maxScore=f[i][j];
if(f[i][j]<minScore) minScore=f[i][j];
}
printf("Delete a maximum score:%.1f\n", maxScore);
printf("Delete a minimum score:%.1f\n", minScore);
a[i].sf=(sum-maxScore-minScore)/(m-2);
printf("The final score of Athlete %d is %.3f\n", a[i].sh, a[i].sf);
}
//计算评委的评分水准
for(j=0; j<m; ++j){
b[j].pf = 0;
for(i=0; i<n; ++i){
b[j].pf+=(f[i][j]-a[i].sf)*(f[i][j]-a[i].sf);
}
b[j].pf=10.0-sqrt(b[j].pf/(float)n);
// b[j].pf=10.0-b[j].pf;
b[j].ph=j+1;
}
//按照最终得分给选手排序
qsort(a, n, sizeof(Athlete), cmpA);
printf("Order of Athletes:\n");
printf("order\tfinal score\tnumber code\n");
for(i=0; i<n; ++i){
printf("%5d\t%11.3f\t%6d\n", i+1, a[i].sf, a[i].sh);
}
//按照评分水准给评委排序
qsort(b, m, sizeof(Judge), cmpJ);
printf("Order of judges:\n");
printf("order\tfinal score\tnumber code\n");
for(j=0; j<m; ++j){
printf("%5d\t%11.3f\t%6d\n", j+1, b[j].pf, b[j].ph);
}
printf("Over!Thank you!\n");
return 0;
}
用例测试结果 运行时间 占用内存 提示 得分
用例1通过 2ms 256kb
4
提交答案本次得分/总分:4.00/4.00分
题目内容:
某班有最多不超过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"
为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。
时间限制:500ms内存限制:32000kb
C
#include
#include
#include
#include
#define MAXN 1000
int n; //represent students number
typedef struct {
long int stuID;
char name[MAXN];
float score;
}STUDENT;
STUDENT stu[MAXN];
//0 代表降序 1代表升序
int cmpByScore1(const void *a, const void *b){
STUDENT *s1 = (STUDENT *)a;
STUDENT *s2 = (STUDENT *)b;
return s1->score - s2->score;
}
int cmpByScore0(const void *a, const void *b){
STUDENT *s1 = (STUDENT *)a;
STUDENT *s2 = (STUDENT *)b;
return s2->score - s1->score;
}
int cmpByNumber0(const void *a, const void *b){
STUDENT *s1 = (STUDENT *)a;
STUDENT *s2 = (STUDENT *)b;
return s2->stuID - s1->stuID;
}
int cmpByNumber1(const void *a, const void *b){
STUDENT *s1 = (STUDENT *)a;
STUDENT *s2 = (STUDENT *)b;
return s1->stuID - s2->stuID;
}
int cmpByName1(const void *a, const void *b){
STUDENT *s1 = (STUDENT *)a;
STUDENT *s2 = (STUDENT *)b;
if(strcmp(s1->name, s2->name) >0 ) return 1;
else return -1;
}
int cmpByName0(const void *a, const void *b){
STUDENT *s1 = (STUDENT *)a;
STUDENT *s2 = (STUDENT *)b;
if(strcmp(s1->name, s2->name) <0 ) return 1;
else return -1;
}
void menu();
void inputRecord();
void calc();
void sortByScore(int order);
void sortByNumber(int order);
void sortByName(int order);
void searchByNumber();
void searchByName();
void analysis();
void print();
void Exit();
int main()
{
printf("Input student number(n<30):\n");
scanf("%d", &n);
while(1){
menu();
}
}
void menu(){
printf("Management for Students' scores\n");
printf("1.Input record\n");
printf("2.Caculate total and average score of course\n");
printf("3.Sort in descending order by score\n");
printf("4.Sort in ascending order by score\n");
printf("5.Sort in ascending order by number\n");
printf("6.Sort in dictionary order by name\n");
printf("7.Search by number\n");
printf("8.Search by name\n");
printf("9.Statistic analysis\n");
printf("10.List record\n");
printf("0.Exit\n");
printf("Please Input your choice:\n");
int choice;
scanf("%d", &choice);
switch(choice){
case 1: inputRecord(); break;
case 2: calc(); break;
case 3: sortByScore(0); break;
case 4: sortByScore(1); break;
case 5: sortByNumber(1); break;
case 6: sortByName(1); break;
case 7: searchByNumber(); break;
case 8: searchByName(); break;
case 9: analysis(); break;
case 10: print(); break;
case 0: Exit();break;
default: printf("Input error!\n");
}
}
void inputRecord(){
printf("Input student's ID, name and score:\n");
int i;
for(i=0; i<n; ++i){
scanf("%ld%s%f", &stu[i].stuID, stu[i].name, &stu[i].score);
}
}
void calc(){
int i;
float sum=0, avg;
for(i=0; i<n; ++i){
sum+=stu[i].score;
}
avg=sum/n;
printf("sum=%.0f,aver=%.2f\n", sum, avg);
}
void sortByScore(int order){
//0 代表降序 1代表升序
if(order){
printf("Sort in ascending order by score:\n");
qsort(stu, n, sizeof(stu[0]),cmpByScore1);
} else {
printf("Sort in descending order by score:\n");
qsort(stu, n, sizeof(stu[0]),cmpByScore0);
}
int i;
for(i=0; i<n; ++i){
printf("%ld\t%s\t%.0f\n", stu[i].stuID, stu[i].name, stu[i].score);
}
}
void sortByNumber(int order){
//0 代表降序 1代表升序
if(order){
printf("Sort in ascending order by number:\n");
qsort(stu, n, sizeof(stu[0]),cmpByNumber1);
} else {
printf("Sort in descending order by number:\n");
qsort(stu, n, sizeof(stu[0]),cmpByNumber0);
}
int i;
for(i=0; i<n; ++i){
printf("%ld\t%s\t%.0f\n", stu[i].stuID, stu[i].name, stu[i].score);
}
}
void sortByName(int order){
//0 代表降序 1代表升序
if(order){
printf("Sort in dictionary order by name:\n");
qsort(stu, n, sizeof(stu[0]),cmpByName1);
} else {
printf("Sort in dictionary order by name:\n");
qsort(stu, n, sizeof(stu[0]),cmpByName0);
}
int i;
for(i=0; i<n; ++i){
printf("%ld\t%s\t%.0f\n", stu[i].stuID, stu[i].name, stu[i].score);
}
}
void searchByNumber(){
printf("Input the number you want to search:\n");
long int id;
scanf("%ld", &id);
int i;
for(i=0; i<n; ++i){
if(stu[i].stuID==id){
printf("%ld\t%s\t%.0f\n", stu[i].stuID, stu[i].name, stu[i].score);
return;
}
}
printf("Not found!\n");
}
void searchByName(){
printf("Input the name you want to search:\n");
char name[MAXN];
scanf("%s", name);
int i;
for(i=0; i<n; ++i){
if(strcmp(stu[i].name, name)==0){
printf("%ld\t%s\t%.0f\n", stu[i].stuID, stu[i].name, stu[i].score);
return;
}
}
printf("Not found!\n");
}
void analysis(){
int i, cnt[6]={0};
for(i=0; i<n; ++i){
if(stu[i].score>=100) cnt[5]++;
else if(stu[i].score>=90) cnt[0]++;
else if(stu[i].score>=80) cnt[1]++;
else if(stu[i].score>=70) cnt[2]++;
else if(stu[i].score>=60) cnt[3]++;
else cnt[4]++;
}
printf("<60\t%d\t%.2f%%\n", cnt[4], 100*(float)cnt[4]/n);
printf("%d-%d\t%d\t%.2f%%\n", 60, 69, cnt[3], 100*(float)cnt[3]/n);
printf("%d-%d\t%d\t%.2f%%\n", 70, 79, cnt[2], 100*(float)cnt[2]/n);
printf("%d-%d\t%d\t%.2f%%\n", 80, 89, cnt[1], 100*(float)cnt[1]/n);
printf("%d-%d\t%d\t%.2f%%\n", 90, 99, cnt[0], 100*(float)cnt[0]/n);
printf("%d\t%d\t%.2f%%\n", 100, cnt[5], 100*(float)cnt[5]/n);
}
void print(){
int i;
for(i=0; i<n; ++i){
printf("%ld\t%s\t%.0f\n", stu[i].stuID, stu[i].name, stu[i].score);
}
}
void Exit(){
printf("End of program!\n");
exit(0);
}
用例测试结果 运行时间 占用内存 提示 得分
用例1通过 2ms 256kb
2
用例2通过 2ms 256kb
2
提交答案本次得分/总分:4.00/4.00分
题目内容:
阿泰和女友小菲用英语短信玩单词接龙游戏。一人先写一个英文单词,然后另一个人回复一个英文单词,要求回复单词的开头有若干个字母和上一个人所写单词的结尾若干个字母相同,重合部分的长度不限。(如阿泰输入happy,小菲可以回复python,重合部分为py。)现在,小菲刚刚回复了阿泰一个单词,阿泰想知道这个单词与自己发过去的单词的重合部分是什么。他们两人都是喜欢写长单词的英语大神,阿泰觉得用肉眼找重合部分实在是太难了,所以请你编写程序来帮他找出重合部分。
程序运行结果示例1:
happy↙
pythen↙
py
程序运行结果示例2:
sun↙
unknown↙
un
输入格式: “%s%s”
输出格式: “%s\n”
为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。
时间限制:500ms内存限制:32000kb
C
#include
#include
#include
#define MAXN 100
int main(){
char a[MAXN], b[MAXN];
scanf("%s%s", a, b);
int i=0, j=0, len=strlen(a);
for(i=0; i<len; ++i){
int start=i;
while(a[i]==b[j] && i<len){
i++, j++;
}
if(i==len){
break;
}
i=start;
j=0;
}
printf("%s\n", a+len-j);
return 0;
}
用例测试结果 运行时间 占用内存 提示 得分
用例1通过 2ms 256kb
2
用例2通过 1ms 256kb
2
提交答案本次得分/总分:4.00/4.00分
题目内容:
比较两个分数的大小。人工方式下比较分数大小最常见的方法是:进行分数的通分后比较分子的大小。可以编程模拟手工解决。
具体要求为首先输出(“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"
为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。
时间限制:500ms内存限制:32000kb
C
#include
#include
#include
#define MAXN 100
int main(){
printf("Input two FENSHU:\n");
int a, b, c, d;
scanf( "%d/%d,%d/%d", &a, &b, &c, &d);
if((float)a/b > (float)c/d){
printf("%d/%d>%d/%d\n", a, b, c, d);
} else if((float)a/b < (float)c/d){
printf("%d/%d<%d/%d\n", a, b, c, d);
} else {
printf("%d/%d=%d/%d\n", a, b, c, d);
}
return 0;
}
用例测试结果 运行时间 占用内存 提示 得分
用例1通过 2ms 256kb
2
用例2通过 14ms 256kb
1
用例3通过 2ms 256kb
1
提交答案本次得分/总分:4.00/4.00分
题目内容:
有一天,一位百万富翁遇到一个陌生人,陌生人找他谈一个换钱的计划,陌生人对百万富翁说:“我每天给你10万元,而你第一天只需给我1分钱,第二天我仍给你10万元,你给我2分钱,第三天我仍给你10万元,你给我4分钱……。你每天给我的钱是前一天的两倍,直到满一个月(30天)为止”,百万富翁很高兴,欣然接受了这个契约。请编程计算在这一个月中陌生人总计给百万富翁多少钱,百万富翁总计给陌生人多少钱。程序中浮点数的数据类型均为double。
输入格式: 无
输出格式:
输出百万富翁给陌生人的钱: “to Stranger: %.2f yuan\n”
输出陌生人给百万富翁的钱: “to Richman: %.2f yuan\n”
为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。
时间限制:500ms内存限制:32000kb
C
#include
#include
#include
#define MAXN 100
int main(){
double s1=0, s2=0, t=0.01;
s1=30*100000;
int i;
for(i=0; i<30; ++i){
s2+=t;
t*=2;
}
printf( "to Stranger: %.2f yuan\n", s2);
printf( "to Richman: %.2f yuan\n", s1);
return 0;
}
用例测试结果 运行时间 占用内存 提示 得分
用例1通过 2ms 256kb
4
提交答案本次得分/总分:4.00/4.00分
题目内容:
输入一些整数,编程计算并输出其中所有正数的和,输入负数时不累加,继续输入下一个数。输入零时,表示输入数据结束。要求最后统计出累加的项数。
程序运行结果示例:
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”
为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。
时间限制:500ms内存限制:32000kb
C
#include
#include
#include
#define MAXN 100
int main(){
int n, sum=0, cnt=0;
printf("Input a number:\n");
scanf("%d", &n);
while(n){
if(n>0) {
sum+=n;
++cnt;
}
printf("Input a number:\n");
scanf("%d", &n);
}
printf( "sum=%d,count=%d\n", sum, cnt);
return 0;
}
用例测试结果 运行时间 占用内存 提示 得分
用例1通过 12ms 256kb
2
用例2通过 1ms 256kb
2
提交答案本次得分/总分:4.00/4.00分
题目内容:
输出100(n2<=100)以内整数的平方根表,n的值要求从键盘输入,并且满足n2<=100 (即n的平方值在100以内)。
程序运行结果示例:
输入提示:“Input n(n<=10):\n”
输入格式: “%d”
输出格式:
输出表头: “%7d”
输出每行的开头数字: “%d”
输出第m行n列中的值:"%7.3f"
为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中
时间限制:500ms内存限制:32000kb
C
#include
#include
#include
#include
#define MAXN 100
int main(){
printf("Input n(n<=10):\n");
int i, j, n, cnt=0;
scanf("%d", &n);
for(i=0; i<n; ++i){
printf("%7d", i);
}
printf("\n");
for(i=0; i<n; ++i){
printf("%d", i);
for(j=0; j<n; ++j){
printf("%7.3f", sqrt(i*10+j));
}
printf("\n");
}
return 0;
}
用例测试结果 运行时间 占用内存 提示 得分
用例1通过 1ms 256kb
1
用例2通过 1ms 256kb
1
用例3通过 1ms 256kb
1
用例4通过 2ms 256kb
1
提交答案本次得分/总分:4.00/4.00分
题目内容:
按照如下函数原型编写子函数计算正整数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”
为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。
时间限制:500ms内存限制:32000kb
C
#include
#include
#include
#include
#define MAXN 10000
int CommonFactors(const int a, const int b){
if (a<=0 || b<=0) return -1;
static int start=MAXN;
for(int i=start; i>0; --i){
if(a%i==0 && b%i==0){
start=i-1;
return i;
}
}
return -1;
}
int main(){
printf("Input a and b:\n");
int a, b, cnt=1, res;
scanf("%d,%d", &a, &b);
res=CommonFactors(a,b);
while(res!=-1){
printf( "Common factor %d is %d\n", cnt++, res);
res = CommonFactors(a,b);
}
return 0;
}
用例测试结果 运行时间 占用内存 提示 得分
用例1通过 2ms 256kb
2
用例2通过 2ms 256kb
1
用例3通过 1ms 256kb
1
提交答案本次得分/总分:4.00/4.00分
题目内容:
请编写一个简单的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”
为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。
时间限制:500ms内存限制:32000kb
C
#include
#include
#include
#include
#define MAXN 10000
int matches=23;
void man(){
int n;
do{
printf("Please enter the number of matches you are moving:\n");
scanf("%d", &n);
if(n>3 || n<=0 || n>matches){
printf("The number you entered is wrong,please re-enter!\n");
}
}while(n>3 || n<=0 || n>matches);
printf("The number of matches you are moving is:%d\n", n);
matches-=n;
printf("The number of matches left is:%d\n", matches);
if(matches==0){
printf("I'm sorry. You lost!\n");
exit(0);
}
}
void machine(){
int n;
if(matches>=3) n=(matches%3+1);
else n=1;
printf("The number of matches that have been moved by the computer is:%d\n", n);
matches-=n;
printf("The number of matches left is:%d\n", matches);
if(matches==0){
printf("Congratulations!You won!\n");
exit(0);
}
}
int main(){
printf("Game start!\n");
printf("Note: the maximum number is 3\n");
while(1){
man();
machine();
}
return 0;
}
用例测试结果 运行时间 占用内存 提示 得分
用例1通过 2ms 256kb
2
用例2通过 2ms 256kb
2
提交答案本次得分/总分:4.00/4.00分