




已阅读5页,还剩44页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
上机考试。一般网站上公布上机环境要求是TC2.0,但实际上是可以使用VC的。这里有一点特别要大家注意:TC2.0只支持纯C代码,不支持C+风格代码。华科的计算机学生称,不管你是用VC还是TC,老师都要在TC2.0上进行验收程序,以确认你的代码是纯C。比如:p = new Node ; 的代码写法在TC2.0下是通不过的,只能写p = (Node *)malloc (sizeof (Node) ; 。另外TC2.0不支持引用,如:Pop (Stack &s , ElemType &e)中含有“&”的引用,在TC2.0下无法通过。华科的上机题目每年都差不多,经常考的就是排序、链表和树的操作等。建议在去复试前一定要进行专门练习上机。08年的华科招收研究生上机试题:(1)输入一个十进制数,将其先转化为八进制数,然后再输出#include main() int a = 0 ; printf (Please enter a decimal number:) ; scanf (%d,&a) ; printf (%ds octal number is %on,a,a) ; (2)用户输入一个文本名,编程实现输出文本中最长的一行和最短的一行。如果最长和最短的不止一行,请全部输出。#include #include #include #define BUFFSIZE 1000 int main()FILE *fp;char filename255;printf(input file name:);scanf(%s,filename);if (NULL=(fp=fopen(filename,r)printf(file open error!);return 0;char LineBUFFSIZEBUFFSIZE;int i=0;int cnt=0;while(fgets(Linei, BUFFSIZE, fp)&iBUFFSIZE) /printf(%s,Linei); i+; cnt+;char tempMaxBUFFSIZE;char tempMinBUFFSIZE; strcpy(tempMax,Line0); strcpy(tempMin,Line0);/printf(%sn,tempMax);for(i=1;istrlen(tempMax) strcpy(tempMax,Linei); if(strlen(Linei)strlen(tempMax) strcpy(tempMin,Linei);int j=-1;printf(longest string:n);for(i=0;icnt;i+) if(strlen(Linei)=strlen(tempMax) printf(%sn,Linei); printf(nnshortest string:n);for(i=0;icnt;i+)if(strlen(Linei)=strlen(tempMin)printf(%s,Linei);fclose(fp);return 0; (3)输入学生信息:学号,三门课程的成绩,学号为0时结束,将其存储在链表A中,从中找出分数大于平均分的学生,并将该学生信息按平均分降序排列存入到链表B中,最后输出链表B。#include #include #include typedef struct nodechar xuehao20;int chengji3;float av;struct node *next;stud,*UerInfo; int main() UerInfo ui; ui=(UerInfo)malloc(sizeof(stud); UerInfo p=ui; UerInfo q=ui; UerInfo tempB=ui; printf(input students information:n); int cnt=0; while (1) printf(input 学号:); scanf(%s,ui-xuehao); if(strcmp(ui-xuehao,0)=0) break; printf(input 成绩:); scanf(%d,&ui-chengji0); printf(input 成绩:); scanf(%d,&ui-chengji1); printf(input 成绩:); scanf(%d,&ui-chengji2); ui-av=(ui-chengji0+ui-chengji1+ui-chengji2)/3); ui-next=(UerInfo)malloc(sizeof(stud); ui=ui-next; cnt+; int chengji1=0; int chengji2=0; int chengji3=0; while (p&strcmp(p-xuehao,0)!=0) chengji1+=p-chengji0; chengji2+=p-chengji1; chengji3+=p-chengji2; p=p-next; float chengji1av=0.0; float chengji2av=0.0; float chengji3av=0.0; float avfinal=0.0; if(cnt) chengji1av=(float)chengji1/(float)cnt; chengji2av=(float)chengji2/(float)cnt; chengji3av=(float)chengji3/(float)cnt; avfinal=(chengji1av+chengji2av+chengji3av)/3; printf(高于平均分的有:n); while (q&strcmp(q-xuehao,0)!=0) if(q-avavfinal) printf(%sn,q-xuehao); printf(%fn,q-av); q=q-next; printf(n降序排列如下:n); UerInfo s; s=(UerInfo)malloc(cnt*sizeof(stud); int k=0; UerInfo temp=tempB; while (tempB&strcmp(tempB-xuehao,0)!=0) sk.av=tempB-av; sk.chengji0=tempB-chengji0; sk.chengji1=tempB-chengji1; sk.chengji2=tempB-chengji2; strcpy(sk.xuehao,tempB-xuehao); tempB=tempB-next; k+; int l,m; stud temps; for (l=0;lcnt-1;l+) for (m=l+1;mcnt;m+) if(sl.avsm.av) temps.chengji0=sl.chengji0;temps.chengji1=sl.chengji1;temps.chengji2=sl.chengji2;strcpy(temps.xuehao,sl.xuehao);sl.chengji0=sm.chengji0; sl.chengji1=sm.chengji1;sl.chengji2=sm.chengji2;strcpy(sl.xuehao,sm.xuehao);sm.chengji0=temps.chengji0;sm.chengji1=temps.chengji1;sm.chengji2=temps.chengji2;strcpy(sm.xuehao,temps.xuehao); for (int i=0;icnt;i+) printf(学号:%sn,si.xuehao); printf(成绩:%fn,si.chengji0); printf(成绩:%fn,si.chengji1); printf(成绩:%fn,si.chengji2); return 0;07年的华科招收研究生上机试题一、 编写一个程序输入一个5X6的矩阵存储并输出,并且求出每行的最大值和每行的总和要求把每行总和放入每行最大值的位置,最后把结果矩阵,每行最大值及其原下标及其总和输出。#include #include int getMat(int a56,int n,int m)int i;int j; for (i=0;in;i+) for(j=0;jm;j+) scanf(%d,&aij); return 0;int getMax(int a56,int n,int m,int b5,int c5,int d5,int sum5)int i;int j;for(i=0;in;i+) bi=0;ci=0;di=0;sumi=0; for(i=0;in;i+)int max=ai0;int col=0;int r=0; for(j=0;jm;j+) sumi+=aij; if(maxaij) max=aij; r=i; col=j; bi=max; ci=r; di=col;for(i=0;in;i+) acidi=sumi;return 0;void displayMat(int a56)int i;int j;for (i=0;i5;i+) printf(n);for(j=0;j6;j+)printf(%d ,aij);printf(n);int main() int a56; getMat(a,5,6); int c5,d5,b5,sum5;getMax(a,5,6,b,c,d,sum);printf(每行最大值:n);for (int i=0;i5;i+) printf(第%d行:n最大值:%dn列:%dn和:%dn,i+1,bi,di,sumi);printf(结果矩阵:n);displayMat(a); return 0;二、 编写程序判断输入的任意字符,任意长度的字符串是否回文(顺读,逆读均相同),最后输出原字符串和判断结果。#include #include #include void main() int i; int bIsSame = 1;/是否相同的标志int a=0,b; char f 255; scanf(%s,f); /读入字符串b = strlen(f)-1; /获得最后一个字符的序号(字符串总长度减)for(i=0;ib/2;i+) /循环,从到字符串中间的字符 if(fa+!=fb-) /首尾比较是否相同字符 bIsSame = 0; /有不同的就把标志置,并跳出循环break; if(bIsSame) /相同就输出Y printf (Y); else /不同就输出N printf (N); getchar();/按任意键退出三、 输入一个6X6的矩阵并存储,把该矩阵逆置并输出。要求:不得使用任何数组(就地逆置)。#include #include void TwoDto1D(int a66,int b36) int i,j; for (i=0;i6;i+) for (j=0;j6;j+) b6*i+j=aij; void TransposeInplace(int b36,int &width,int &height)int from, to, offset, step;int i, j;for (i = to = offset = 0, step = width; i width; +i, -step, offset += height-1) for (j = 0, from = i + offset; j height; +j, +to, from += step) int temp;temp=bto;bto=bfrom;bfrom=temp;/bto=bfrom;int temp;temp=width;width=height;height=temp;int getMat(int a66,int n,int m)int i;int j; for (i=0;in;i+) for(j=0;jm;j+) scanf(%d,&aij); return 0;void display(int b36) for (int i=0;i36;i+) if (i%6=0) printf(n); printf(%d ,bi); int main() int a66; int b36; getMat(a,6,6); TwoDto1D(a,b); int width=6; int height=6; TransposeInplace(b,width,height); display(b); return 0;06年的华科研究生复试上机试题:(1)采用命令行方式复制任意多个文件内容到一个文件中,如下所示:命令行形式:mycopy 1.txt 2.txt 3.txt 4.txt .功能:复制2.txt 3.txt 4.txt 的内容到1.txt中#include #include #include #define BUFFERSIZE 1000int main(int argc, char *argv) if (argc3) printf(参数不足n); return 0; /int cnt=argc-1;int i;FILE *fp;if(NULL=(fp=fopen(argv1,a) printf(目标文件打开失败!); return 0;fprintf(fp,%s,n);FILE *fpSRC;for (i=2;iargc;i+) if(NULL=(fpSRC=fopen(argvi,r) printf(源文件打开失败!); return 0; char tempBUFFERSIZE+1;while (fgets(temp,BUFFERSIZE,fpSRC) fprintf(fp,%sn,temp);fclose(fpSRC);printf(内容复制成功!n);fclose(fp);return 0;(2)判定一个C语言变量的命名是否正确#include int check(char *str) char *temp=str; if (!(*temp=_|(*temp=a&*temp=A&*temp=a&*temp=A&*temp=0&*temp=9) return 0; temp+; return 1;int main() while(1) printf(input var:); char haha255; scanf(%s,haha); if(check(haha) printf(CORRECTn); else printf(WRONGn); return 0;(3)建立一种数据结构,可以存储任意个、任意长度的整数,利用这个数据结构,输入一串数,排序,求累加和#include #include #include typedef struct node int i; struct node *next; struct node *pre;bigIntNode,*bigInt;bigInt getBigInt(char *s) bigInt bi; bi=(bigInt)malloc(sizeof(bigIntNode); bi-pre=NULL; bigInt temp=bi; char *p=s; while(*p!=0) bi-i=*p-0;/太浪费了吧,一个字符存储一下子 bi-next=(bigInt)malloc(sizeof(bigIntNode); bigInt t=bi; bi=bi-next; bi-pre=t; p+; bi-next=NULL; return temp;int display(bigInt bi) bigInt p=bi; if(p-i) printf(%d,p-i); p=p-next; while(p-next) printf(%d,p-i); p=p-next; printf(n); return 1;bigInt add(bigInt bi1,bigInt bi2) bigInt p=bi1; bigInt q=bi2; while (p-next) p=p-next; while (q-next) q=q-next; bigInt ret=(bigInt)malloc(sizeof(bigIntNode); ret-next=NULL; ret-i=0; int finali=0; int add=0; while (p&q) int i=p-i+q-i; int t=0; int j=0; if(i9) j=i/10;t=i%10; else j=0; t=i; ret-i=t; bigInt tb=(bigInt)malloc(sizeof(bigIntNode); tb-i=0; tb-i+=j; ret-pre=tb; tb-next=ret; ret=tb; p=p-pre; q=q-pre; finali=j; if(p) int f=0; while(p) f=p-i+ret-i; int t=0; int j=0; if(f9) j=f/10; t=f%10; else j=0; t=f; ret-i=t; bigInt tb=(bigInt)malloc(sizeof(bigIntNode); tb-i=0; tb-i+=j; ret-pre=tb; tb-next=ret; ret=tb; p=p-pre; if(q) int f=0; while(q) f=q-i+ret-i; int t=0; int j=0; if(f9) j=f/10; t=f%10; else j=0; t=f; ret-i=t; bigInt tb=(bigInt)malloc(sizeof(bigIntNode); tb-i=0; tb-i+=j; ret-pre=tb; tb-next=ret; ret=tb; q=q-pre; ret-pre=NULL; return ret;int getlength(bigInt bi) bigInt p=bi; int i=0; while(p) p=p-next; i+; return i;int compare(bigInt bi1,bigInt bi2) bigInt p=bi1; bigInt q=bi2; if (getlength(p)getlength(q) return 1; else if (getlength(p)next,q=q-next) if (p-iq-i) return 1; else if (p-ii) return -1; return 0; int sort(bigInt *bi,int n) int i; int j; for (i=0;in-1;i+) bigInt temp; for (j=i+1;jn;j+) if (compare(bii,bij) memcpy(temp,bii,sizeof(bigInt);memcpy(bii,bij,sizeof(bigInt);memcpy(bij,bii,sizeof(bigInt); return 0;int main() bigInt *bia; bia=(bigInt*)malloc(1000*sizeof(bigInt); int cnt=0; char str1000; printf(输入大数n); for (int i=0;i1000;i+) scanf(%s,str); if(strcmp(str,0)=0) break; biai=getBigInt(str); cnt+; bigInt sum=bia0; for(int i=1;icnt;i+) sum=add(sum,biai); printf(原来大数:n); for(int i=0;icnt;i+) display(biai); sort(bia,cnt); printf(排序后大数:n); for(int i=0;icnt;i+) display(biai); printf(和:n); display(sum); return 0;05-03年华科招收研究生复试上机试题汇总:(1)输入一个数列以0为结束标志,建立链式线性表,查找其中最大的数并输出删除释放节点,然后对剩余的进行排序,并输出释放节点。#include #include typedef struct node int value; struct node *next;LNode,*SqList;void createList(SqList &L) SqList p=L; while (1) int value; scanf(%d,&value); if (value=0) p=NULL; return; p-value=value; p-next=(SqList)malloc(sizeof(LNode); p=p-next; void display(SqList L) SqList p=L; while (p-value!=-1163005939) printf(%d ,p-value); SqList q=p-next; free(p); p=q; int getMax(SqList L) if (L) SqList p=L; int temp=p-value; p=p-next; while (p&p-value!=-1163005939) if (tempvalue) temp=p-value; p=p-next; return temp; void freeMax(SqList &L) if (L) SqList p=L; SqList q; while (p) if (p-value=getMax(L) q=p-next; free(p); L=q; break; p=p-next; void SortSqList(SqList &L) SqList p,q,small; int temp; for (p=L;p-next;p=p-next) small=p; for(q=p-next;q;q=q-next) if(q-valuevalue) small=q; if (small!=p) temp=p-value; p-value=q-value; q-value=temp; int main() SqList L;L=(SqList)malloc(sizeof(LNode); createList(L);int max=getMax(L);printf(最大值:%dn,max);freeMax(L);SortSqList(L);printf(排序后:n);display(L);(2)输入一个数列以0为结束标志,建立二叉遍历树,并对其进行逆中序遍历,释放空间。#include #include typedef struct tnodeint value;struct tnode *lchild;struct tnode *rchild;BTreeNode,*BTree;BTree createBTree()int value;BTree t;scanf(%d,&value);if (value=0) /* 判断当前子树是否创建完成*/ return NULL; else t=(BTree)malloc(sizeof(BTreeNode);t-value=value;t-lchild=createBTree();t-rchild=createBTree();return t;void ReInorderBTree(BTree B) BTree p=B; if(p) InorderBTree(p-rchild); printf(%dn,p-value); free(p); InorderBTree(p-lchild); int main() printf(输入整数,以结尾n); BTree B=createBTree(); printf(中序遍历如下:n); ReInorderBTree(B); return 0;(3)给出年分m和一年中的第n天,算出第n天是几月几号(提示中给出了判断闰年的方法),按 yyyy-mm-dd的格式打印出来#include#includevoid main()int ping12=31,28,31,30,31,30,31,31,30,31,31;int rui12=31,29,31,30,31,30,31,31,30,31,31;unsigned int year,days;int month,day,*p=ping;printf(please input the year:);scanf(%d,&year);printf(please input the days:);scanf(%d,&days);if(year%4=0&year%100!=0)p=rui;else if(year%100=0&year%400=0)p=rui;for(month=0,day=0;month=days)break;if(month12)if(day=days)day=pmonth;elseday=day-pmonth;day=days-day;printf(the date is %d-%d-%d,year,month+1,day);elseprintf(wrong input!);getch();。 (4)职工有职工号,姓名,年龄.输入n个职工的信息,找出3个年龄最小的职工打印出来,n可以取6。(5)n个人排一圈123报数,报到3的人退到圈外,直到剩最后一个人为止。#include #include struct node int data; struct node * link; *list,*p,*r; void JOSEPHUS(int n,int m,int k); int main() int n,k; printf(请输入人数:); scanf(%d,&n); printf(n请输入从哪里开始:); scanf(%d,&k); /*printf(n请输入数到:); scanf(%d,&m); */ if(n!=0) JOSEPHUS(n,3,k); system(PAUSE); return 0; void JOSEPHUS(int n,int m,int k) int i; for (i=1;idata=i; if(list=NULL) list=p; else r-link=p; r=p; p-link=list; p=list; for (i=1;ilink; while(p-link!=p) for(i=1;ilink; r-link=p-link; printf(%dn,p-data); free(p); p=r-link; printf(n最后被删除结点是%dn,p-data); (6)冒泡排序。#define N 10#include int bublesort(int aN)int i,j,change,temp;for (i=N-1,change=1;i=1&change;-i) change=0; for(j=0;j
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年物流管理专业理论知识考试试题及答案
- 2025年社区工作者职称考试试题及答案
- 2025年社会心理学师职称考试试题及答案
- 2025年教师资格证考试题及答案
- 2025年法律职业资格考试题及答案
- 2025年城市管理与服务能力考试题及答案
- 2024年度浙江省护师类之主管护师能力提升试卷A卷附答案
- 2024年度浙江省二级注册建筑师之法律法规经济与施工通关试题库(有答案)
- 2024年度浙江省二级造价工程师之土建建设工程计量与计价实务模拟题库及答案下载
- 实验室监督人员培训
- 个体工商户转让协议(2篇)
- 胸痛中心胸痛随访数据采集表
- 体检机构服务流程
- 水工混凝土建筑物修补加固技术规程
- 经皮冠状动脉介入治疗术术后健康饮食宣教
- 【语文】福建省厦门市演武小学小学二年级下册期末试题
- 2021-2022学年山东省东营市广饶县七年级(下)期末英语试卷(五四学制)(附答案详解)
- 卧式常压热水锅炉使用说明书
- (完整版)新人教版英语七年级下册单词听写表
- 酒店住宿水单模板2020
- 物业公司权责手册市场拓展
评论
0/150
提交评论