华中科技大学计算机学院上机复试题目.docx
《华中科技大学计算机学院上机复试题目.docx》由会员分享,可在线阅读,更多相关《华中科技大学计算机学院上机复试题目.docx(36页珍藏版)》请在冰豆网上搜索。
华中科技大学计算机学院上机复试题目
上机考试。
一般网站上公布上机环境要求是TC2.0,但实际上是可以使用VC的。
这里有一点特别要大家注意:
TC2.0只支持纯C代码,不支持C++风格代码。
华科的计算机学生称,不管你是用VC还是TC,老师都要在TC2.0上进行验收程序,以确认你的代码是纯C。
比如:
p=newNode;的代码写法在TC2.0下是通不过的,只能写p=(Node*)malloc(sizeof(Node));。
另外TC2.0不支持引用,如:
Pop(Stack&s,ElemType&e)中含有“&”的引用,在TC2.0下无法通过。
华科的上机题目每年都差不多,经常考的就是排序、链表和树的操作等。
建议在去复试前一定要进行专门练习上机。
08年的华科招收研究生上机试题:
(1)输入一个十进制数,将其先转化为八进制数,然后再输出
#include
main()
{
inta=0;
printf("Pleaseenteradecimalnumber:
");
scanf("%d",&a);
printf("%d'soctalnumberis%o\n",a,a);
}
(2)用户输入一个文本名,编程实现输出文本中最长的一行和最短的一行。
如果最长和最短的不止一行,请全部输出。
#include
#include
#include
#defineBUFFSIZE1000
intmain()
{
FILE*fp;
charfilename[255];
printf("inputfilename:
");
scanf("%s",filename);
if(NULL==(fp=fopen(filename,"r")))
{
printf("fileopenerror!
");
return0;
}
charLine[BUFFSIZE][BUFFSIZE];
inti=0;
intcnt=0;
while((fgets(Line[i],BUFFSIZE,fp))&&i{
//printf("%s",Line[i]);
i++;
cnt++;
}
chartempMax[BUFFSIZE];
chartempMin[BUFFSIZE];
strcpy(tempMax,Line[0]);
strcpy(tempMin,Line[0]);
//printf("%s\n",tempMax);
for(i=1;i{
if(strlen(Line[i])>strlen(tempMax))
strcpy(tempMax,Line[i]);
if(strlen(Line[i])strcpy(tempMin,Line[i]);
}
intj=-1;
printf("longeststring:
\n");
for(i=0;i{
if(strlen(Line[i])==strlen(tempMax))
{
printf("%s\n",Line[i]);
}
}
printf("\n\nshorteststring:
\n");
for(i=0;i{
if(strlen(Line[i])==strlen(tempMin))
{
printf("%s",Line[i]);
}
}
fclose(fp);
return0;
}
(3)输入学生信息:
学号,三门课程的成绩,学号为0时结束,将其存储在链表A中,从中找出分数大于平均分的学生,并将该学生信息按平均分降序排列存入到链表B中,最后输出链表B。
#include
#include
#include
typedefstructnode
{charxuehao[20];intchengji[3];floatav;structnode*next;
}stud,*UerInfo;
intmain()
{
UerInfoui;
ui=(UerInfo)malloc(sizeof(stud));
UerInfop=ui;
UerInfoq=ui;
UerInfotempB=ui;
printf("inputstudents'information:
\n");
intcnt=0;
while
(1)
{
printf("input学号:
");
scanf("%s",ui->xuehao);
if(strcmp(ui->xuehao,"0")==0)
break;
printf("input成绩:
");
scanf("%d",&ui->chengji[0]);
printf("input成绩:
");
scanf("%d",&ui->chengji[1]);
printf("input成绩:
");
scanf("%d",&ui->chengji[2]);
ui->av=((ui->chengji[0]+ui->chengji[1]+ui->chengji[2])/3);
ui->next=(UerInfo)malloc(sizeof(stud));
ui=ui->next;
cnt++;
}
intchengji1=0;
intchengji2=0;
intchengji3=0;
while(p&&strcmp(p->xuehao,"0")!
=0)
{
chengji1+=p->chengji[0];
chengji2+=p->chengji[1];
chengji3+=p->chengji[2];
p=p->next;
}
floatchengji1av=0.0;
floatchengji2av=0.0;
floatchengji3av=0.0;
floatavfinal=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->av>avfinal)
{
printf("%s\n",q->xuehao);
printf("%f\n",q->av);
}
q=q->next;
}
printf("\n降序排列如下:
\n");
UerInfos;
s=(UerInfo)malloc(cnt*sizeof(stud));
intk=0;
UerInfotemp=tempB;
while(tempB&&strcmp(tempB->xuehao,"0")!
=0)
{
s[k].av=tempB->av;
s[k].chengji[0]=tempB->chengji[0];
s[k].chengji[1]=tempB->chengji[1];
s[k].chengji[2]=tempB->chengji[2];
strcpy(s[k].xuehao,tempB->xuehao);
tempB=tempB->next;
k++;
}
intl,m;
studtemps;
for(l=0;l{
for(m=l+1;m{
if(s[l].av
{
temps.chengji[0]=s[l].chengji[0];
temps.chengji[1]=s[l].chengji[1];
temps.chengji[2]=s[l].chengji[2];
strcpy(temps.xuehao,s[l].xuehao);
s[l].chengji[0]=s[m].chengji[0];
s[l].chengji[1]=s[m].chengji[1];
s[l].chengji[2]=s[m].chengji[2];
strcpy(s[l].xuehao,s[m].xuehao);
s[m].chengji[0]=temps.chengji[0];
s[m].chengji[1]=temps.chengji[1];
s[m].chengji[2]=temps.chengji[2];
strcpy(s[m].xuehao,temps.xuehao);
}
}
}
for(inti=0;i{
printf("学号:
%s\n",s[i].xuehao);
printf("成绩:
%f\n",s[i].chengji[0]);
printf("成绩:
%f\n",s[i].chengji[1]);
printf("成绩:
%f\n",s[i].chengji[2]);
}
return0;
}
07年的华科招收研究生上机试题
一、编写一个程序输入一个5X6的矩阵存储并输出,并且求出每行的最大值和每行的总和要求把每行总和放入每行最大值的位置,最后把结果矩阵,每行最大值及其原下标及其总和输出。
#include
#include
intgetMat(inta[5][6],intn,intm)
{
inti;
intj;
for(i=0;i{
for(j=0;j{
scanf("%d",&a[i][j]);
}
}
return0;
}
intgetMax(inta[5][6],intn,intm,intb[5],intc[5],intd[5],intsum[5])
{
inti;
intj;
for(i=0;i{
b[i]=0;
c[i]=0;
d[i]=0;
sum[i]=0;
}
for(i=0;i{
intmax=a[i][0];
intcol=0;
intr=0;
for(j=0;j{
sum[i]+=a[i][j];
if(maxmax=a[i][j];
r=i;
col=j;
}
b[i]=max;
c[i]=r;
d[i]=col;
}
for(i=0;i{
a[c[i]][d[i]]=sum[i];
}
return0;
}
voiddisplayMat(inta[5][6])
{
inti;
intj;
for(i=0;i<5;i++)
{
printf("\n");
for(j=0;j<6;j++)
{
printf("%d",a[i][j]);
}
}
printf("\n");
}
intmain()
{
inta[5][6];
getMat(a,5,6);
intc[5],d[5],b[5],sum[5];
getMax(a,5,6,b,c,d,sum);
printf("每行最大值:
\n");
for(inti=0;i<5;i++)
{
printf("第%d行:
\n最大值:
%d\n列:
%d\n和:
%d\n",i+1,b[i],d[i],sum[i]);
}
printf("结果矩阵:
\n");
displayMat(a);
return0;
}
二、编写程序判断输入的任意字符,任意长度的字符串是否回文(顺读,逆读均相同),最后输出原字符串和判断结果。
#include
#include
#include
voidmain()
{
inti;
intbIsSame=1;//是否相同的标志
inta=0,b;
charf[255];
scanf("%s",f);//读入字符串
b=strlen(f)-1;//获得最后一个字符的序号(字符串总长度减)
for(i=0;i
{
if(f[a++]!
=f[b--])//首尾比较是否相同字符
{
bIsSame=0;//有不同的就把标志置,并跳出循环
break;
}
}
if(bIsSame)//相同就输出Y
printf("Y");
else//不同就输出N
printf("N");
getchar();//按任意键退出
}
三、输入一个6X6的矩阵并存储,把该矩阵逆置并输出。
要求:
不得使用任何数组(就地逆置)。
#include
#include
voidTwoDto1D(inta[6][6],intb[36])
{
inti,j;
for(i=0;i<6;i++)
{
for(j=0;j<6;j++)
{
b[6*i+j]=a[i][j];
}
}
}
voidTransposeInplace(intb[36],int&width,int&height)
{
intfrom,to,offset,step;
inti,j;
for(i=to=offset=0,step=width;ifor(j=0,from=i+offset;jinttemp;
temp=b[to];
b[to]=b[from];
b[from]=temp;
//b[to]=b[from];
}
}
inttemp;
temp=width;
width=height;
height=temp;
}
intgetMat(inta[6][6],intn,intm)
{
inti;
intj;
for(i=0;i{
for(j=0;j{
scanf("%d",&a[i][j]);
}
}
return0;
}
voiddisplay(intb[36])
{
for(inti=0;i<36;i++)
{
if(i%6==0)
{
printf("\n");
}
printf("%d",b[i]);
}
}
intmain()
{
inta[6][6];
intb[36];
getMat(a,6,6);
TwoDto1D(a,b);
intwidth=6;
intheight=6;
TransposeInplace(b,width,height);
display(b);
return0;
}
==》06年的华科研究生复试上机试题:
(1)采用命令行方式复制任意多个文件内容到一个文件中,如下所示:
命令行形式:
mycopy1.txt2.txt3.txt4.txt...
功能:
复制2.txt3.txt4.txt…的内容到1.txt中
#include
#include
#include
#defineBUFFERSIZE1000
intmain(intargc,char*argv[])
{
if(argc<3)
{
printf("参数不足\n");
return0;
}
//intcnt=argc-1;
inti;
FILE*fp;
if(NULL==(fp=fopen(argv[1],"a")))
{
printf("目标文件打开失败!
");
return0;
}
fprintf(fp,"%s","\n");
FILE*fpSRC;
for(i=2;i{
if(NULL==(fpSRC=fopen(argv[i],"r")))
{
printf("源文件打开失败!
");
return0;
}
chartemp[BUFFERSIZE+1];
while(fgets(temp,BUFFERSIZE,fpSRC))
{
fprintf(fp,"%s\n",temp);
}
fclose(fpSRC);
}
printf("内容复制成功!
\n");
fclose(fp);
return0;
}
(2)判定一个C语言变量的命名是否正确
#include
intcheck(char*str)
{
char*temp=str;
if(!
(*temp=='_'||(*temp>='a'&&*temp<='z')||(*temp>='A'&&*temp<='Z')))
{
return0;
}
temp++;
while(*temp!
='\0')
{
if(!
(*temp=='_'||(*temp>='a'&&*temp<='z')||(*temp>='A'&&*temp<='Z')||(*temp>='0'&&*temp<='9')))
{
return0;
}
temp++;
}
return1;
}
intmain()
{
while
(1)
{
printf("inputvar:
");
charhaha[255];
scanf("%s",haha);
if(check(haha))
printf("CORRECT\n");
else
printf("WRONG\n");
}
return0;
}
(3)建立一种数据结构,可以存储任意个、任意长度的整数,利用这个数据结构,输入一串数,排序,求累加和
#include
#include
#include
typedefstructnode
{
inti;
structnode*next;
structnode*pre;
}bigIntNode,*bigInt;
bigIntgetBigInt(char*s)
{
bigIntbi;
bi=(bigInt)malloc(sizeof(bigIntNode));
bi->pre=NULL;
bigInttemp=bi;
char*p=s;
while(*p!
='\0')
{
bi->i=*p-‘0’;//太浪费了吧,一个字符存储一下子
bi->next=(bigInt)malloc(sizeof(bigIntNode));
bigIntt=bi;
bi=bi->next;
bi->pre=t;
p++;
}
bi->next=NULL;
returntemp;
}
intdisplay(bigIntbi)
{
bigIntp=bi;
if(p->i)
{
printf("%d",p->i);
}
p=p->next;
while(p->next)
{
printf("%d",p->i);
p=p->next;
}
printf("\n");
return1;
}
bigIntadd(bigIntbi1,bigIntbi2)
{
bigIntp=bi1;
bigIntq=bi2;
while(p->next)
{
p=p->next;
}
while(q->next)
{
q=q->next;
}
bigIntret=(bigInt)malloc(sizeof(bigIntNode));
ret->next=NULL;
ret->i=0;
intfinali=0;
intadd=0;
while(p&&q)
{
inti=p->i+q->i;
intt=0;
intj=0;
if(i>9)
{
j=i/10;
t=i%10;
}
else
{
j=0;
t=i;
}
ret->i=t;
bigInttb=(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)
{
intf=0;
while(p)