收藏 分享(赏)

竞赛题(难)答案.doc

上传人:scg750829 文档编号:6366504 上传时间:2019-04-09 格式:DOC 页数:10 大小:73KB
下载 相关 举报
竞赛题(难)答案.doc_第1页
第1页 / 共10页
竞赛题(难)答案.doc_第2页
第2页 / 共10页
竞赛题(难)答案.doc_第3页
第3页 / 共10页
竞赛题(难)答案.doc_第4页
第4页 / 共10页
竞赛题(难)答案.doc_第5页
第5页 / 共10页
点击查看更多>>
资源描述

1、一、 选择题CCBBD CADAC DBCDB二、 简答题1、 有,全局变量储存在静态数据库,局部变量在堆栈2、 满二叉树:也称丰满二叉树,一棵深度(高度) 为 h 且有 2h-1 个结点的二叉树;不完全二叉树:前 n 层满足完全二叉树结构,第 n-1 层不满足完全二叉树结构的叫做不完全二叉树平衡二叉树:被称为 AVL 树(区别于 AVL 算法) ,它是一棵二叉排序树,且具有以下性质:它是一棵空 树或它的左右两个子树的高度差的绝对值不超过 1,并且左右两个子树都是一棵平衡二叉树;。3、 O(n2);分析过程:假设排序的数共有 n 个,共需要进行 n 趟排序,第一趟排序要比较的次数为 n-1次,

2、第二趟排序要比较的次数为 n-2 次,依次类推,最后一趟排序比较次数为 1 次,所以比较次数为1+2+3+(n-1)=n*(n-1)/2,这个时间复杂度为 O(n2)。4、 区别:全局变量,全局有效,局部变量,局部有效;能重命名,局部会屏蔽全局。要用全局变量,需要使用“:“5、 可以,可以在不同的 C 文件中以 static 形式来声明同名全局变量。6、 方法 1:int main()char* src = “hello,world“;int len = strlen(src);char* dest = (char*)malloc(len+1);/要为0 分配一个空间char* d = des

3、t;char* s = /指向最后一个字符while( len- != 0 )*d+=*s-;*d = 0;/尾部要加 0printf(“%sn“,dest);free(dest);/ 使用完,应当释放空间,以免造成内存汇泄露return 0;方法 2:#include #include main()char str=“hello,world“;int len=strlen(str);char t;for(int i=0; i1)break;if(n%2=0)printf(“Even=“);sum=dcall(peven,n);elseprintf(“Odd=“);sum=dcall(podd

4、,n);printf(“%f“,sum);float peven(int n)float s;int i;s=1;for(i=2;i #include struct S char name20; /*姓名*/int number; /*学号*/float score_yuwen; /*语文成绩*/ float score_shuxue; /*数学成绩*/float score_yingyu; /*英语成绩*/T; /*建立学生成绩信息的结构体*/*信息维护=将学生信息数据以文件的形式保存*/void writefile(T *student,int n) FILE *fp; int i,j;

5、if(fp=fopen(“d:kanwei.txt“,“w+“)=NULL) printf(“cant open file“); exit(0); for(i=0;inumberp1=p1-next; /*p1 后移一个结点 */ if(number=p1-number) if(p1=head)head=p1-next;/*若 p1 指向的是首结点,把后一个结点地址赋予 head*/else p2-next=p1-next;/*否则将下一个结点地址赋给前一结点地址*/printf(“删除:%dn“,number);n=n-1;elseprintf(“%d 不存在此学生!n“,number);/

6、*找不到该结点*/ endifprintf(“已经删除了!n“)printf(“现在的学生数为:%d 个!n“,n);return(head); /*信息维护=修改学生信息*/void modify(T *student,int n,) delet(student,n,); addfile(student,n); /*信息查询=按学生姓名查询*/int find1(T *student,int n,int *tp) char name20;int i;printf(“输入要查询的学生的名字:”);scanf(“%s,namen”);for(i=0;iscore2)i=score1;score1

7、=score2;score2=i;if(class=yuwen)yuwen(T*student,n+1,score1,score2);if(class=shuxue)shuxue(T*student,n+1,score1,score2);if(class=yingyu)yingyu(T*student,n+1,score1,score2);/*=按语文成绩统计=*/void yuwen(T*student,int n+1,int score1,int score2)int i,j,a,b;for(i=0;istudentj.score_yuwen)studentn+1=studenti;stu

8、denti=studentj;studentj=studentn+1;for(i=0;istudentj.score_shuxue)studentn+1=studenti;studenti=studentj;studentj=studentn+1;for(i=0;istudentj.score_yingyu)studentn+1=studenti;studenti=studentj;studentj=studentn+1;for(i=0;i=n;i+)if(studenti.score_yingyu=score1)a=i;if(studenti.score_yingyu=score2)b=i;

9、for(i=a;i=b;i+)printf(“%s %d %f %f %fn”,studenti.name,studenti.number,studenti.score_yuwen,studenti.score_shuxue,studenti.score_yingyu);return()/*=显示成绩=*/void display(T *student,int *tp,int n) int i,j; char a3=“ “; printf(“*n“); printf(“ name number grade class average ordern“); for(i=0;in;i+) print

10、f(“-n“); printf(“%d:n“,i+1); printf(“ %s %d %d %d %f %dn“,studenttpi.name,studenttpi.number,studenttpi.grade,studenttpi.class,studenttpi.average,tpi+1); printf(“mark:“); for(j=0;j2;j+) printf(“%s%d:%f“,a,j+1,studenttpi.markj); printf(“n“); void main() /* 主程序 */ int i=1; while(i) printf(“ Choose the operate:n“); printf(“*n“); printf(“ find add delete modify showall exitn“); printf(“ 1 2 3 4 5 0n“); printf(“*n“); scanf(“%d“, readfile(i);

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 中等教育 > 竞赛课件

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报