C++面试题题库资料_第1页
C++面试题题库资料_第2页
C++面试题题库资料_第3页
C++面试题题库资料_第4页
C++面试题题库资料_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

C++面试题

1、给定字符串A和B,输出A和B中的最大公共子串,C++面试题

O

比如此aocdfeB=pmcdfa则输出cdf

*/

//Author:azhen

#includestdio.h

#includestdlib.h

#includestring.h

char*commanstring(charshortstringf],charlongstring[])

{

inti,j;

char*substring=malloc(256);

if(strstr(longstring,shortstring)!=NULL)〃假如,那么返回

shortstring

returnshortstring:

for(i=strlen(shortstring)-l;iO;i-)//否则,开头循环计算

(

for(j=0;j=strlen(shortstring)-i;j++){

memcpy(substring,shortstring[j],i);

substring[i]=\O;

if(strstr(longstring,substring)!=NULL)

returnsubstring;

)

returnNULL;

千里之行,始于足下。

)

main()

(

char*strl=malloc(256);

char*str2=mal1oc(256);

char*comman=NULL;

gets(strl);

gets(str2);

if(strlcn(strl)strlen(str2))//将短的字符串放前面

conunan=commanstring(str2,strl);

else

coinman=commanstring(strl,str2);

printf(thelongestcommanstringis:%s\n,coinman);

}

2、写一个函数比较两个字符串strl和str2的大小,若相等返回0,

若strl大于str2返回1,若strl小于str2返回一1

intstrcmp(constchar*src,constchar*dst)

(

intret=0;

while(!(ret=*(unsignedchar*)src-*(unsignedchar*)dst)

*dst)

{

++src;

++dst;

)

if(ret0)

ret=-1;

elseif(ret0)

ret=1;

return(ret);

}

第2页/共6页

3、求1000!的未尾有几个0(用素数相乘的方法来做,如

72=2*2*2*3*3);

求出1T000里,能被5整除的数的.个数nl,能被25整除的数的

个数n2,能被125整除的数的个数n3,

能被625整除的数的个数n4.

1000!末尾的零的个数=nl+n2+n3+n4;

#includestdio.h

#defineNUM1000

intfind5(intnum){

intret=0;

while(num%5-0){

num/=5;

ret++;

}

returnret;

)

intmain(){

intresult=0;

inti;

for(i=5;i=NUM;i+=5)

(

result+=find5(i);

)

printf(thetotalzeronumberis%d\n,result);

return0;

)

4、有双向循环链表结点定义为:

structnode

{intdata;

structnode*front,*nexl;

};

千里之行,始于足下。

有两个双向循环链表A,B,知道其头指针为:pHeadA,pHeadB,请写

一函数将两链表中data值相同的结点删除

BOOLDeteleNode(Node*plleader,DataTypeValue)

(

if(pHeader==NULL)return;

BOOLbRet=FALSE;

Node*pNode=pHead;

while(pNode!=NULL)

(

if(pNode-data==Value)

(

if(pNode-front==NULL)

{

pHeader=pNode-next;

pHeader-front=NULL;

)

else

(

if(pNode-next!=NULL)

(

pNodo-ncxt-front=pNodo-front;

)

pNode-front-next=pNode-next;

)

Node*pNextNode=pNode-next;

deletepNode;

pNode=pNextNode;

bRet=TRUE;

〃不要break或return,删除全部

)

else

第4页/共6页

pNode=pNode-next;

returnbRet;

}

voidDE(Node*pHeadA,Node*pHeadB)

(

if(pHeadA=NULL||pHeadB==NULL)

{

return;

)

Node*pNode=pHeadA;

while(pNode!=NULL)

(

if(DeteleNode(pHeadB,pNode-data))

(

if(pNode-front==NULL)

(

pHeadA=pNode-next;

pHoadA-front=NULL;

)

else

{

pNode-front-next=pNode-next;

if(pNode-next!=NULL)

(

pNode-next-front-pNode-front;

}

}

Node*pNexiNode=pNode-next;

千里之行,始于足

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论