1 / 16
文档名称:

计算机常见算法面试题.docx

格式:docx   大小:19KB   页数:16页
下载后只包含 1 个 DOCX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

计算机常见算法面试题.docx

上传人:shugezhang1 2022/6/5 文件大小:19 KB

下载得到文件列表

计算机常见算法面试题.docx

文档介绍

文档介绍:简介:计算机考研之家搜集的华为C语言经典面试题,来试试你的C语言水平吧。每道题 都附有详细解答和讲解,很有参考价值的C语言面试题。
怎么判断链表中是否有环?
bool CkcleIiiList(LHik* pHead)
{
if(p,那么返回 shoitstriiig
return shoitstrmg;
fbr(i=stikn(shortstring)・l;i>0; i-) 〃否则,开始循环计算
{
j<=stilen(shortstimg)-i; j++){
memcpy(substnng, &shonstriiig[j], i);
substriiig[i]=,\O,;
if(stistr(longstring, substring)! =NULL) return substring;
}
}
return NULL;
}
main()
{
char *strl=nialloc(256);
char *str2=nialloc(256);
char *conmiaii=NULL;
gets(strl);
gets(str2);
if(sulen(sti- l)>strlen(str2)) 〃将短的字符串放前面
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
hit sticmp (const char * src,const char * dst)
{
hit 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整除的数的个数nl,能被25整除的数的个数n2,能被125整除的数的 个数113,
能被625整除的数的个数n4.
1000!末尾的零的个数=nl+n2+n3+n4;
#iiiclude
#define NUM 1000
mt find 5 (hit num)(
mt ret=O;
wliile(num% 5==0)(
num--5;
iet++;
}
return ret;
}
hit mam()(
mt 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
{ mt data;
stmct node *fiont,*next;
};
有两个双向循环链表A, B,知道其头指针为:pHeadA^pHeadB,请写一函数将两链表中data 值相同的结点删除
BOOL DeteleNode(Node *pHeader, DataType Value)
{
if (pHeadei == NULL) return;
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或return,删除所有
} e