文档介绍:简介:计算机考研之家搜集的华为C语言经典面试题,来试试你的C语言水平吧。每道题 都附有详细解答和讲解,很有参考价值的C语言面试题。
怎么判断链表中是否有环?
bool CiicleIiiList(LHik* pHead)
{
if( //如果 ,那么返回 shoitstriiig
return shoitstrmg;
fbr(i=strlen(shortstring)-l;i>0; i~) //否则,开始循环计算
j<=stilen(shortstimg)-i; j++){ memcpv(substnng, &shoitstrmg[j], i); substrmg[i]=,\O,;
if(stistr(longstrmg, substring)! =NULL) return substring;
return NULL; } main() char *strl=nialloc(256); char *str2=nialloc(256);
char *conmiaii=NULL;
gets(strl); gets(str2);
if(stilen(su-1 )>strlen(sti2)) 〃将短的字符串放前面
conunan=conmiaiistiing(sti2, stil);
else
conunan=conmiaiistiing(sti l, sti2);
printf(Mthe longest conmian string is: %s\iT; coniinan);
}
,若相等返回0,若strl人于
str2返回1,若strl小于str2返回一1
iiit sticmp (const char * src,const char * dst)
{
iiit ret = 0 ;
wliile(! (ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst)
{
++src;
++dst;
}
if(iet<0)
ret = -1 ;
else if (ret > 0 )
ret= 1 ;
return( ret);
}
3,求1000!的未尾有几个0 (用素数相乘的方法来做,如72=2*2*2*3*3);
求出1->1000里,能被5整除的数的个数ill,能被25整除的数的个数n2,能被125整除的数的 个数113,
能被625整除的数的个数114.
1000!末尾的零的个数=口 1+112+113+114;
# include
#define NUM 1000
mt fiiid5(iiit num){
iiit ret=O;
wliile(num% 5==0){
num--5;
iet++;
}
return ret;
}
iiit main(){
iiit result=0;
inti;
fbr(i=5 ;i<=NUM;i+=5)
iesult+=fiiid5(i);
}
printf(M the total zero number is %d\n,\result); leturn 0;
}
有双向循坏链表结点定义为:
stmct node
{iiit data;
stmct node *fiont,*next;
};
有两个双向循坏链表A, B,知道其头指针为:pHeadA^pHeadB,请写一函数将两链表中data 值相同的结点删除
BOOL DeteleNode(Node *pHeader, DataType Value)
{
if (pHeadei == NULL) retuin;
BOOL bRet = FALSE;
Node *pNode =pHead;
wliile (pNode != NULL)
{
if (pNode->data == Value)
{
if (pNode->fiont = NULL)
{
pHeader = pNode->next;
pHeader->fiont = NULL;
}
else
{
if (pNode->next != NULL)
{
pNode->next->fiont = pNode->fiont;
}
pNode->fiont->next = pNode->next;
}
Node *pNextNode = pNode->next; delete pNode;
pNode = pNextNode;
bRet = TRUE;
〃不要break或retiun,删除所有
}
el