华中科技大学计算机学院上机复试题目
- 格式:doc
- 大小:153.00 KB
- 文档页数:49
上机考试。一般网站上公布上机环境要求是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 ("%d's octal number is %o\n",a,a) ;
}
(2)用户输入一个文本名,编程实现输出文本中最长的一行和最短的一行。如果最长和最短的不止一行,请全部输出。
#include
#include
#include
#define BUFFSIZE 1000
int main()
{
FILE *fp;
char filename[255]; printf("input file name:");
scanf("%s",filename);
if (NULL==(fp=fopen(filename,"r")))
{
printf("file open error!");
return 0;
}
char Line[BUFFSIZE][BUFFSIZE];
int i=0;
int cnt=0;
while((fgets(Line[i], BUFFSIZE, fp))&&i
{
//printf("%s",Line[i]);
i++;
cnt++;
}
char tempMax[BUFFSIZE];
char tempMin[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]);
}
int j=-1;
printf("longest string:\n");
for(i=0;i
{
if(strlen(Line[i])==strlen(tempMax))
{
printf("%s\n",Line[i]);
}
}
printf("\n\nshortest string:\n");
for(i=0;i
{
if(strlen(Line[i])==strlen(tempMin))
{
printf("%s",Line[i]); }
}
fclose(fp);
return 0;
}
(3)输入学生信息:学号,三门课程的成绩,学号为0时结束,将其存储在链表A中,从中找出分数大于平均分的学生,并将该学生信息按平均分降序排列存入到链表B中,最后输出链表B。
#include
#include
#include
typedef struct node
{char xuehao[20];int chengji[3];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->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++;
}
int chengji1=0;
int chengji2=0;
int chengji3=0;
while (p&&strcmp(p->xuehao,"0")!=0)
{
chengji1+=p->chengji[0]; chengji2+=p->chengji[1];
chengji3+=p->chengji[2];
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->av>avfinal)
{
printf("%s\n",q->xuehao);
printf("%f\n",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)
{
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++;
}
int l,m;
stud temps;
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 (int i=0;i
{
printf("学号:%s\n",s[i].xuehao);