题目内容:
某班有最多不超过30人(具体人数由键盘输入)参加期末考试,最多不超过6门(具体门数由键盘输入)。参考学生成绩管理系统V4.0,定义结构体类型,用结构体数组作函数参数,编程实现如下菜单驱动的学生成绩管理系统:
(1)录入每个学生的学号、姓名和各科考试成绩;
(2)计算每门课程的总分和平均分;
(3)计算每个学生的总分和平均分;
(4)按每个学生的总分由高到低排出名次表;
(5)按每个学生的总分由低到高排出名次表;
(6)按学号由小到大排出成绩表;
(7)按姓名的字典顺序排出成绩表;
(8)按学号查询学生排名及其考试成绩;
(9)按姓名查询学生排名及其考试成绩;
(10)按优秀(90100)、良好(8089)、中等(7079)、及格(6069)、不及格(0~59)5个类别,对每门课程分别统计每个类别的人数以及所占的百分比;
(11)输出每个学生的学号、姓名、各科考试成绩,以及每门课程的总分和平均分。
要求程序运行后先显示如下菜单,并提示用户输入选项:
Management for Students’ scores
1.Input record
2.Caculate total and average score of every course
3.Caculate total and average score of every student
4.Sort in descending order by score
5.Sort in ascending order by score
6.Sort in ascending order by number
7.Sort in dictionary order by name
8.Search by number
9.Search by name
10.Statistic analysis
11.List record
0.Exit
Please Input your choice:
然后,根据用户输入的选项执行相应的操作。
下面是程序运行示例:
Input student number(n<30):
6↙
Management for Students’ scores
1.Input record
2.Caculate total and average score of every course
3.Caculate total and average score of every student
4.Sort in descending order by score
5.Sort in ascending order by score
6.Sort in ascending order by number
7.Sort in dictionary order by name
8.Search by number
9.Search by name
10.Statistic analysis
11.List record
0.Exit
Please Input your choice:
1↙
Input course number(m<=6):
3↙
Input student’s ID, name and score:
11003001↙
lisi↙
87↙
82↙
89↙
11003005↙
heli↙
98↙
92↙
90↙
11003003↙
ludi↙
75↙
78↙
80↙
11003002↙
dumo↙
48↙
50↙
67↙
11003004↙
zuma↙
65↙
69↙
72↙
11003006↙
suyu↙
100↙
95↙
94↙
Management for Students’ scores
1.Input record
2.Caculate total and average score of every course
3.Caculate total and average score of every student
4.Sort in descending order by score
5.Sort in ascending order by score
6.Sort in ascending order by number
7.Sort in dictionary order by name
8.Search by number
9.Search by name
10.Statistic analysis
11.List record
0.Exit
Please Input your choice:
2↙
course 1:sum=473,aver=79
course 2:sum=466,aver=78
course 3:sum=492,aver=82
Management for Students’ scores
1.Input record
2.Caculate total and average score of every course
3.Caculate total and average score of every student
4.Sort in descending order by score
5.Sort in ascending order by score
6.Sort in ascending order by number
7.Sort in dictionary order by name
8.Search by number
9.Search by name
10.Statistic analysis
11.List record
0.Exit
Please Input your choice:
3↙
student 1: sum=258,aver=86
student 2: sum=280,aver=93
student 3: sum=233,aver=78
student 4: sum=165,aver=55
student 5: sum=206,aver=69
student 6: sum=289,aver=96
Management for Students’ scores
1.Input record
2.Caculate total and average score of every course
3.Caculate total and average score of every student
4.Sort in descending order by score
5.Sort in ascending order by score
6.Sort in ascending order by number
7.Sort in dictionary order by name
8.Search by number
9.Search by name
10.Statistic analysis
11.List record
0.Exit
Please Input your choice:
4↙
Sort in descending order by score:
11003006 suyu 100 95 94 289 96
11003005 heli 98 92 90 280 93
11003001 lisi 87 82 89 258 86
11003003 ludi 75 78 80 233 78
11003004 zuma 65 69 72 206 69
11003002 dumo 48 50 67 165 55
Management for Students’ scores
1.Input record
2.Caculate total and average score of every course
3.Caculate total and average score of every student
4.Sort in descending order by score
5.Sort in ascending order by score
6.Sort in ascending order by number
7.Sort in dictionary order by name
8.Search by number
9.Search by name
10.Statistic analysis
11.List record
0.Exit
Please Input your choice:
5↙
Sort in ascending order by score:
11003002 dumo 48 50 67 165 55
11003004 zuma 65 69 72 206 69
11003003 ludi 75 78 80 233 78
11003001 lisi 87 82 89 258 86
11003005 heli 98 92 90 280 93
11003006 suyu 100 95 94 289 96
Management for Students’ scores
1.Input record
2.Caculate total and average score of every course
3.Caculate total and average score of every student
4.Sort in descending order by score
5.Sort in ascending order by score
6.Sort in ascending order by number
7.Sort in dictionary order by name
8.Search by number
9.Search by name
10.Statistic analysis
11.List record
0.Exit
Please Input your choice:
6↙
Sort in ascending order by number:
11003001 lisi 87 82 89 258 86
11003002 dumo 48 50 67 165 55
11003003 ludi 75 78 80 233 78
11003004 zuma 65 69 72 206 69
11003005 heli 98 92 90 280 93
11003006 suyu 100 95 94 289 96
Management for Students’ scores
1.Input record
2.Caculate total and average score of every course
3.Caculate total and average score of every student
4.Sort in descending order by score
5.Sort in ascending order by score
6.Sort in ascending order by number
7.Sort in dictionary order by name
8.Search by number
9.Search by name
10.Statistic analysis
11.List record
0.Exit
Please Input your choice:
7↙
Sort in dictionary order by name:
11003002 dumo 48 50 67 165 55
11003005 heli 98 92 90 280 93
11003001 lisi 87 82 89 258 86
11003003 ludi 75 78 80 233 78
11003006 suyu 100 95 94 289 96
11003004 zuma 65 69 72 206 69
Management for Students’ scores
1.Input record
2.Caculate total and average score of every course
3.Caculate total and average score of every student
4.Sort in descending order by score
5.Sort in ascending order by score
6.Sort in ascending order by number
7.Sort in dictionary order by name
8.Search by number
9.Search by name
10.Statistic analysis
11.List record
0.Exit
Please Input your choice:
8↙
Input the number you want to search:
11003007↙
Not found!
Management for Students’ scores
1.Input record
2.Caculate total and average score of every course
3.Caculate total and average score of every student
4.Sort in descending order by score
5.Sort in ascending order by score
6.Sort in ascending order by number
7.Sort in dictionary order by name
8.Search by number
9.Search by name
10.Statistic analysis
11.List record
0.Exit
Please Input your choice:
8↙
Input the number you want to search:
11003004↙
11003004 zuma 65 69 72 206 69
Management for Students’ scores
1.Input record
2.Caculate total and average score of every course
3.Caculate total and average score of every student
4.Sort in descending order by score
5.Sort in ascending order by score
6.Sort in ascending order by number
7.Sort in dictionary order by name
8.Search by number
9.Search by name
10.Statistic analysis
11.List record
0.Exit
Please Input your choice:
9↙
Input the name you want to search:
lili↙
Not found!
Management for Students’ scores
1.Input record
2.Caculate total and average score of every course
3.Caculate total and average score of every student
4.Sort in descending order by score
5.Sort in ascending order by score
6.Sort in ascending order by number
7.Sort in dictionary order by name
8.Search by number
9.Search by name
10.Statistic analysis
11.List record
0.Exit
Please Input your choice:
9↙
Input the name you want to search:
lisi↙
11003001 lisi 87 82 89 258 86
Management for Students’ scores
1.Input record
2.Caculate total and average score of every course
3.Caculate total and average score of every student
4.Sort in descending order by score
5.Sort in ascending order by score
6.Sort in ascending order by number
7.Sort in dictionary order by name
8.Search by number
9.Search by name
10.Statistic analysis
11.List record
0.Exit
Please Input your choice:
10↙
For course 1:
<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%
For course 2:
<60 1 16.67%
60-69 1 16.67%
70-79 1 16.67%
80-89 1 16.67%
90-99 2 33.33%
100 0 0.00%
For course 3:
<60 0 0.00%
60-69 1 16.67%
70-79 1 16.67%
80-89 2 33.33%
90-99 2 33.33%
100 0 0.00%
Management for Students’ scores
1.Input record
2.Caculate total and average score of every course
3.Caculate total and average score of every student
4.Sort in descending order by score
5.Sort in ascending order by score
6.Sort in ascending order by number
7.Sort in dictionary order by name
8.Search by number
9.Search by name
10.Statistic analysis
11.List record
0.Exit
Please Input your choice:
11↙
11003002 dumo 48 50 67 165 55
11003005 heli 98 92 90 280 93
11003001 lisi 87 82 89 258 86
11003003 ludi 75 78 80 233 78
11003006 suyu 100 95 94 289 96
11003004 zuma 65 69 72 206 69
Management for Students’ scores
1.Input record
2.Caculate total and average score of every course
3.Caculate total and average score of every student
4.Sort in descending order by score
5.Sort in ascending order by score
6.Sort in ascending order by number
7.Sort in dictionary order by name
8.Search by number
9.Search by name
10.Statistic analysis
11.List record
0.Exit
Please Input your choice:
12↙
Input error!
Management for Students’ scores
1.Input record
2.Caculate total and average score of every course
3.Caculate total and average score of every student
4.Sort in descending order by score
5.Sort in ascending order by score
6.Sort in ascending order by number
7.Sort in dictionary order by name
8.Search by number
9.Search by name
10.Statistic analysis
11.List record
0.Exit
Please Input your choice:
0↙
End of program!
输入格式:
( 1 )录入学生的人数:
**要求输入数据格式为:"%d"
**提示信息为:"Input student number(n<30):\n"
( 2 )录入课程数:
**要求输入数据格式为:"%d"
**提示信息为:"Input course number(m<=%d):\n"
( 3 )录入每个学生的学号、姓名和考试成绩:
**要求学号、姓名的输入数据格式为:"%ld%s"
**要求考试成绩的输入数据格式为:"%f"
**提示信息为:"Input student's ID, name and score:\n"
输出格式:
计算每门课程的总分和平均分:
**要求输出总分与平均分格式为:"course %d:sum=%.0f,aver=%.0f\n"
计算每个学生的总分和平均分:
**要求输出总分与平均分格式为:"student %d: sum=%.0f,aver=%.0f\n"
按成绩由高到低排出名次表:
**要求学号、姓名的输出格式为:"%ld\t%s\t"
**要求成绩的输出格式为:"%.0f\t"
**要求总分及平均分的输出格式为:"%.0f\t%.0f\n"
**提示信息为:"Sort in descending order by score:\n"
按成绩由低到高排出名次表:
**要求学号、姓名的输出格式为:"%ld\t%s\t"
**要求成绩的输出格式为:"%.0f\t"
**要求总分及平均分的输出格式为:"%.0f\t%.0f\n"
**提示信息为:"Sort in ascending order by score:\n"
按学号由小到大排出成绩表:
**要求学号、姓名的输出格式为:"%ld\t%s\t"
**要求成绩的输出格式为:"%.0f\t"
**要求总分及平均分的输出格式为:"%.0f\t%.0f\n"
**提示信息为:"Sort in ascending order by number:\n"
按姓名的字典顺序排出成绩表
**要求学号、姓名的输出格式为:"%ld\t%s\t"
**要求成绩的输出格式为:"%.0f\t"
**要求总分及平均分的输出格式为:"%.0f\t%.0f\n"
**提示信息为:"Sort in dictionary order by name:\n"
按学号查询学生排名及其考试成绩:
**如果未查到此学号的学生,提示信息为:"Not found!\n";
**如果查询到该学生
# 要求学号、姓名的输出格式为:"%ld\t%s\t"
# 要求成绩的输出格式为:"%.0f\t"
# 要求总分及平均分的输出格式为:"%.0f\t%.0f\n"
**提示信息为:"Input the number you want to search:\n"
按姓名查询学生排名及其考试成绩;
**如果未查到此学号的学生,提示信息为:"Not found!\n";
**如果查询到该学生
# 要求学号、姓名的输出格式为:"%ld\t%s\t"
# 要求成绩的输出格式为:"%.0f\t"
# 要求总分及平均分的输出格式为:"%.0f\t%.0f\n"
**提示信息为:"Input the name you want to search:\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"
**提示信息为: "For course %d:\n"
输出每个学生的学号、姓名、考试成绩,以及课程总分和平均分
**要求学号、姓名的输出格式为:"%ld\t%s\t"
**要求成绩的输出格式为:"%.0f\t"
**要求总分及平均分的输出格式为:"%.0f\t%.0f\n"
选择退出(菜单项0)
**提示信息:"End of program!"
菜单项选择错误(不在0-11之间)
**提示信息:"Input error!\n"
为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。
程序的主要框架如下,请将主函数里的函数调用语句中缺少的实参、以及自定义函数中的函数体(用…替代的部分)补充完整。
#include
#include
#include
#define MAX_LEN 10 /* 字符串最大长度 */
#define STU_NUM 30 /* 最多的学生人数 */
#define COURSE_NUM 6 /* 最多的考试科目数 */
typedef struct student
{
long num; /* 每个学生的学号 */
char name[MAX_LEN]; /* 每个学生的姓名 */
float score[COURSE_NUM]; /* 每个学生COURSE_NUM门功课的成绩 */
float sum; /* 每个学生的总成绩 */
float aver; /* 每个学生的平均成绩 */
}STU;
int Menu(void);
void ReadScore(STU stu[], int n, int m);
void AverSumofEveryStudent(STU stu[], int n, int m);
void AverSumofEveryCourse(STU stu[], int n, int m);
void SortbyScore(STU stu[],int n,int m,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(STU stu[], int n, int m);
void SortbyName(STU stu[], int n, int m);
void SearchbyNum(STU stu[], int n, int m);
void SearchbyName(STU stu[], int n, int m);
void StatisticAnalysis(STU stu[], int n, int m);
void PrintScore(STU stu[], int n, int m);
int main()
{
char ch;
int n = 0, m = 0; /* 学生人数为n,课程门数为m */
STU stu[STU_NUM];
printf("Input student number(n<=30):\n", STU_NUM);
scanf("%d", &n);
while (1)
{
ch = Menu(); /* 显示菜单,并读取用户输入 */
switch (ch)
{
case 1:
printf("Input course number(m<=%d):\n",COURSE_NUM);
scanf("%d", &m);
ReadScore(..........);
break;
case 2:
AverSumofEveryCourse(..........);
break;
case 3:
AverSumofEveryStudent(..........);
break;
case 4:
SortbyScore(..........);
printf("Sort in descending order by score:\n");
PrintScore(..........);
break;
case 5:
SortbyScore(..........);
printf("Sort in ascending order by score:\n");
PrintScore(..........);
break;
case 6:
AsSortbyNum(..........);
printf("Sort in ascending order by number:\n");
PrintScore(..........);
break;
case 7:
SortbyName(..........);
printf("Sort in dictionary order by name:\n");
PrintScore(..........);
break;
case 8:
SearchbyNum(..........);
break;
case 9:
SearchbyName(..........);
break;
case 10:
StatisticAnalysis(..........);
break;
case 11:
PrintScore(..........);
break;
case 0:
printf("End of program!");
exit(0);
default: printf("Input error!\n");
}
}
return 0;
}
/* 函数功能:显示菜单并获得用户键盘输入的选项 */
int Menu(void)
{
..........
}
/* 函数功能:输入n个学生的m门课成绩 */
void ReadScore(STU stu[], int n, int m)
{
..........
}
/* 函数功能:计算每个学生各门课程的总分和平均分 */
void AverSumofEveryStudent(STU stu[], int n, int m)
{
..........
}
/* 函数功能:计算每门课程的总分和平均分 */
void AverSumofEveryCourse(STU stu[], int n, int m)
{
..........
}
/* 函数功能:按选择法将数组sum的元素值排序 */
void SortbyScore(STU stu[], int n, int m, 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[])
{
..........
}
/* 函数功能:按选择法将数组num的元素值按从低到高排序 */
void AsSortbyNum(STU stu[], int n, int m)
{
..........
}
/* 函数功能:交换法实现字符串按字典顺序排序 */
void SortbyName(STU stu[], int n, int m)
{
..........
}
/* 函数功能:按学号查找学生成绩并显示查找结果 */
void SearchbyNum(STU stu[], int n, int m)
{
..........
}
/* 函数功能:按姓名的字典顺序排出成绩表 */
void SearchbyName(STU stu[], int n, int m)
{
..........
}
/* 函数功能:统计各分数段的学生人数及所占的百分比 */
void StatisticAnalysis(STU stu[], int n, int m)
{
..........
}
/* 函数功能: 打印学生成绩 */
void PrintScore(STU stu[], int n, int m)
{
..........
}
时间限制:500ms内存限制:32000kb
C
#include
#include
#include
#include
#define MAX_LEN 10 /* 字符串最大长度 */
#define STU_NUM 30 /* 最多的学生人数 */
#define COURSE_NUM 6 /* 最多的考试科目数 */
int n; //represent students number
int m; //课程数
float sum[COURSE_NUM], aver[COURSE_NUM];//每门课程的总分和成绩
typedef struct student{
long int stuID;
char name[MAX_LEN];
float score[COURSE_NUM];
float sum, aver;
}STUDENT;
STUDENT stu[STU_NUM];
//0 代表降序 1代表升序
int cmpByScore1(const void *a, const void *b){
STUDENT *s1 = (STUDENT *)a;
STUDENT *s2 = (STUDENT *)b;
return s1->sum - s2->sum;
}
int cmpByScore0(const void *a, const void *b){
STUDENT *s1 = (STUDENT *)a;
STUDENT *s2 = (STUDENT *)b;
return s2->sum - s1->sum;
}
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 calcStudent();
void calcCourse();
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 every course\n");
printf("3.Caculate total and average score of every student\n");
printf("4.Sort in descending order by score\n");
printf("5.Sort in ascending order by score\n");
printf("6.Sort in ascending order by number\n");
printf("7.Sort in dictionary order by name\n");
printf("8.Search by number\n");
printf("9.Search by name\n");
printf("10.Statistic analysis\n");
printf("11.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: calcCourse(); break;
case 3: calcStudent(); break;
case 4: sortByScore(0); break;
case 5: sortByScore(1); break;
case 6: sortByNumber(1); break;
case 7: sortByName(1); break;
case 8: searchByNumber(); break;
case 9: searchByName(); break;
case 10: analysis(); break;
case 11: print(); break;
case 0: Exit();break;
default: printf("Input error!\n");
}
}
void inputRecord(){
printf("Input course number(m<=6):\n");
scanf("%d", &m);
printf("Input student's ID, name and score:\n");
int i, j;
for(i=0; i<n; ++i){
scanf("%ld%s", &stu[i].stuID, stu[i].name);
stu[i].sum=0;
for(j=0; j<m; ++j){
scanf("%f",&stu[i].score[j]);
stu[i].sum+=stu[i].score[j];
}
stu[i].aver=stu[i].sum/(float)m;
}
}
void calcCourse(){
int i, j;
for(j=0; j<m; ++j){//第j门课程
sum[j]=0;
for(i=0; i<n; ++i){//第i个学生
sum[j]+=stu[i].score[j];
}
aver[j]=sum[j]/(float)n;
printf("course %d:sum=%.0f,aver=%.0f\n",j+1, sum[j], aver[j]);
}
}
void calcStudent(){
for(int i=0; i<n; ++i){
printf("student %d:sum=%.0f,aver=%.0f\n", i+1, stu[i].sum, stu[i].aver);
}
}
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);
}
print();
}
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);
}
print();
}
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);
}
print();
}
void searchByNumber(){
printf("Input the number you want to search:\n");
long int id;
scanf("%ld", &id);
int i, j;
for(i=0; i<n; ++i){
if(stu[i].stuID==id){
printf("%ld\t%s\t", stu[i].stuID, stu[i].name);
for(j=0; j<m; ++j){
printf("%.0f\t", stu[i].score[j]);
}
printf("%.0f\t%.0f\n", stu[i].sum, stu[i].aver);
return;
}
}
printf("Not found!\n");
}
void searchByName(){
printf("Input the name you want to search:\n");
char name[MAX_LEN];
scanf("%s", name);
int i, j;
for(i=0; i<n; ++i){
if(strcmp(stu[i].name, name)==0){
printf("%ld\t%s\t", stu[i].stuID, stu[i].name);
for(j=0; j<m; ++j){
printf("%.0f\t", stu[i].score[j]);
}
printf("%.0f\t%.0f\n", stu[i].sum, stu[i].aver);
return;
}
}
printf("Not found!\n");
}
void analysis(){
int i, j;
for(j=0; j<m; ++j){
printf( "For course %d:\n", j+1);
int cnt[6]={0};
for(i=0; i<n; ++i){
if(stu[i].score[j]>=100) cnt[5]++;
else if(stu[i].score[j]>=90) cnt[0]++;
else if(stu[i].score[j]>=80) cnt[1]++;
else if(stu[i].score[j]>=70) cnt[2]++;
else if(stu[i].score[j]>=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, j;
for(i=0; i<n; ++i){
printf("%ld\t%s\t", stu[i].stuID, stu[i].name );
for(j=0; j<m; ++j){
printf("%.0f\t", stu[i].score[j]);
}
printf("%.0f\t%.0f\n", stu[i].sum, stu[i].aver);
}
}
void Exit(){
printf("End of program!\n");
exit(0);
}
用例测试结果 运行时间 占用内存 提示 得分
用例1未通过 0ms 0kb
结果错误
0
用例2未通过 0ms 0kb
结果错误
0
提交答案本次得分/总分:0.00/4.00分
这题有点问题,我并没用用官方给的程序框架,是我自己想的一个框架,我通过了前面V4.0的测试但是这里测试被卡住了。可能有什么特殊情况被卡住了,虽然没有拿到分数,但是我更愿意展示自己的代码 ,而不是一份通过的代码。相比而言我的代码实现相同的功能,代码复用程度也高,代码量更少。
题目内容:
编写一个函数,对一个字符串中的字符进行升序排序,并输出字符排序后的字符串,字符串长度小于20。
程序运行结果如下:
Input a string:
friend↙
definr
输入提示信息:“Input a string:\n”
输入格式:
字符串输入采用:gets()函数
输出格式:"%s"
为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。
时间限制:500ms内存限制:32000kb
C
#include
#include
#include
int cmp(const void *a, const void *b){
return *(char *)a-*(char *)b;
}
int main(){
printf("Input a string:\n");
char str[100];
gets(str);
qsort(str, strlen(str), sizeof(str[0]), cmp);
puts(str);
return 0;
}
用例测试结果 运行时间 占用内存 提示 得分
用例1通过 2ms 256kb
1
用例2通过 2ms 256kb
1
用例3通过 1ms 256kb
2
提交答案本次得分/总分:4.00/4.00分
题目内容:
按给定函数原型编程检查一个字符串是否全由数字组成。
int IsAllDigit(char p[]);/若全由数字组成,则函数返回1,否则返回0/
在主函数中,从键盘输入一个字符串(假设字符串的最大长度为20个字符),调用函数IsAllDigit(),检查该字符串是否全由数字组成,然后在主函数中根据函数IsAllDigit()的返回值输出相应的提示信息。
程序运行结果示例1:
Please input a string:
help456↙
The string is not digit string.
程序运行结果示例2:
Please input a string:
20150216↙
The string is digit string.
字符串输入提示信息:“Please input a string:\n”
输入格式: 字符串输入采用 gets()函数
输出格式:
判断是纯数字字符串:“The string is digit string.”
判断不是纯数字字符串:“The string is not digit string.”
为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。
时间限制:500ms内存限制:32000kb
C
#include
#include
#include
#include
int IsAllDigit(char p[]){
for(int i=0; p[i]; ++i){
if(!isdigit(p[i])){
return 0;
}
}
return 1;
}
int main(){
printf("Please input a string:\n");
char str[100];
gets(str);
if(IsAllDigit(str)){
printf("The string is digit string.");
} else {
printf("The string is not digit string.");
}
return 0;
}
用例测试结果 运行时间 占用内存 提示 得分
用例1通过 2ms 256kb
2
用例2通过 2ms 128kb
1
用例3通过 2ms 128kb
1
提交答案本次得分/总分:4.00/4.00分
题目内容:
相差为2的两个素数称为孪生素数。例如,3与5,41与43等都是孪生素数。设计程序求出指定区间上的所有孪生素数对。区间上限和下限由键盘获取。
程序运行示例如下:
please input c,d(c>2):
10,200↙
(11,13)
(17,19)
(29,31)
(41,43)
(59,61)
(71,73)
(101,103)
(107,109)
(137,139)
(149,151)
(179,181)
(191,193)
(197,199)
total=13
区间上限和下限的输入提示信息:“please input c,d(c>2):\n”
输入格式:
区间上限和下限的输入格式: “%ld,%ld”
输出格式:
孪生素数的输出格式:"(%ld,%ld)\n"
所有孪生素数对的总数输出格式: “total=%d\n”
为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。
时间限制:500ms内存限制:32000kb
C
#include
#include
#include
#include
#define MAXN 10000
int a[MAXN];
int p[MAXN];
int main(){
long c, d;
printf("please input c,d(c>2):\n");
scanf("%ld,%ld", &c, &d);
for(int i=2; i<MAXN; ++i){
a[i]=i;
}
for(int i=2; i<sqrt(MAXN); ++i){
for(int j=i+1; j<MAXN; ++j){
if(a[i]!=0 && a[j]!=0 && a[j]%a[i]==0){
a[j]=0;
}
}
}
int k=0, j;
for(int i=2; i<MAXN; ++i){
if(a[i]){
p[k++]=a[i];
}
}
int total=0;
for( j=1; j<k; ++j){
if(p[j]<=d&&p[j-1]>=c&&p[j]-p[j-1]==2){
printf("(%ld,%ld)\n", p[j-1], p[j]);
++total;
}
}
printf("total=%d\n", total);
return 0;
}
用例测试结果 运行时间 占用内存 提示 得分
用例1通过 3ms 360kb
1
用例2通过 3ms 364kb
2
用例3通过 3ms 236kb
1
提交答案本次得分/总分:4.00/4.00分
题目内容:
对指定正实数n(采用双精度浮点型表示),试求满足下面平方根不等式的最小整数m,并输出不等式左边的值。程序中浮点数的数据类型均为double。
程序运行示例如下:
Input n:
5.1↙
Result:m>=2
s=5.15
输入提示信息:“Input n:\n”
输入格式: “%lf”
输出格式:
整数m的输出格式:“Result:m>=%d\n”
不等式左边的值的输出格式:“s=%.2f\n”
为避免出现格式错误,请直接拷贝粘贴题目中给的格式字符串和提示信息到你的程序中。
时间限制:500ms内存限制:32000kb
C
#include
#include
#include
#include
#define MAXN 10000
double func(int m){
double sum=0;
for(int i=0; i<=m; ++i){
sum+=sqrt(m+i);
}
return sum;
}
int main(){
double n;
printf("Input n:\n");
scanf("%lf", &n);
int i=0;
while(func(i)<=n) i++;
printf("Result:m>=%d\n", i);
printf("s=%.2f\n", func(i));
return 0;
}
用例测试结果 运行时间 占用内存 提示 得分
用例1通过 1ms 128kb
1
用例2通过 1ms 128kb
1
用例3通过 1ms 128kb
1
用例4通过 1ms 128kb
1
提交答案本次得分/总分:4.00/4.00