劳动模范事迹材料-欣然自得
华为
C
语言经典面试题。每道题都附有详细解答和讲解,很有参考价值的
C< br>语言面试题。
怎么判断链表中是否有环?
bool CircleInList(Link* pHead)
{
if(pHead = = NULL || pHead->next = = NULL)//
无节点或只有一个节点并且无自环
return (false);
if(pHead->next = = pHead)//
自环
return (true);
Link *pTemp1 = pHead;//step 1
Link *pTemp = pHead->next;//step 2
while(pTemp != pTemp1 && pTemp != NULL && pTemp->next != NULL)
{
pTemp1 = pTemp1->next;
pTemp = pTemp->next->next;
}
if(pTemp = = pTemp1)
return (true);
return (false);
}
两个字符串 ,
s,t;
把
t
字符串插入到
s
字符串中,
s字符串有足够的空间存放
t
字符串
void insert(char *s, char *t, int i)
{
memcpy(&s[strlen(t)+i],&s[i],strlen(s)-i);
memcpy(&s[i],t,strlen(t));
s[strlen(s)+strlen(t)]='0';
}
1
。编写一个
C
函数,该函数在一个字符 串中找到可能的最长的子字符串,且该字符串是
由同一字符组成的。
char * search(char *cpSource, char ch)
{
char *cpTemp=NULL, *cpDest=NULL;
int iTemp, iCount=0;
while(*cpSource)
{
if(*cpSource == ch)
{
iTemp = 0;
cpTemp = cpSource;
while(*cpSource == ch)
++iTemp, ++cpSource;
if(iTemp > iCount)
iCount = iTemp, cpDest = cpTemp;
if(!*cpSource)
break;
}
++cpSource;
}
return cpDest;
}
2
。请编写一个
C
函数,该函数在给定的内存区域搜索给定的字符,并返回该字符所在位
置索引值。
int search(char *cpSource, int n, char ch)
{
int i;
for(i=0; ireturn i;
}
一个单向链表,不知 道头节点
,
一个指针指向其中的一个节点,问如何删除这个指针指向的
节点?
将这个指针指向的
next
节点值
copy
到本节点,< br>将
next
指向
next->next,
并随后删除原
nex t
指向的节点。
#include
void foo(int m, int n)
{
printf(
}
int main()
{
int b = 3;
foo(b+=3, ++b);
printf(
return 0;
}
输出:
m=7,n=4,b=7(VC6.0)
这种方式和编译器中得函数调用关系相关即先后入栈顺序。不过不同
编译器得处理不同。也是因为
C
标准中对这种方式说明为未定义,所以
各个编译器厂商都有自己得理解,所以最后产生得结果完全不同。
因为这样,所以遇见这种函数,我们首先要考虑我们得编译器会如何处理
这样得函数,其次看函数得调用方式,不同得调用方式,可能产生不同得
结果。最后是看编译器优化。
2.
写一函数,实现删除字符串
str1
中含有的字符串
str2.
第二个就是利用一个
KMP
匹配算法找到
str2
然后删 除(用链表实现的话,便捷于数组)
//Author: azhen
#include
#include
#include
char *commanstring(char shortstring[], char longstring[])
{
int i, j;
char *substring=malloc(256);
if(strstr(longstring, shortstring)!=NULL) //
如果
……
,那么返回
shortstring
return shortstring;
for(i=strlen(shortstring)-1;i>0; i--) //
否则,开始循环计算
{
for(j=0; j<=strlen(shortstring)-i; j++){
memcpy(substring, &shortstring[j], i);
substring[i]='0';
if(strstr(longstring, substring)!=NULL)
return substring;
}
}
return NULL;
}
main()
{
char *str1=malloc(256);
char *str2=malloc(256);
char *comman=NULL;
gets(str1);
gets(str2);
if(strlen(str1)>strlen(str2)) //
将短的字符串放前面
comman=commanstring(str2, str1);
else
comman=commanstring(str1, str2);
printf(
}
11.
写一个函数比较两个字符串
str1
和
str2
的大小,若 相等返回
0
,若
str1
大于
str2
返回
1
,若
str1
小于
str2
返回-
1
int strcmp ( const char * src,const char * dst)
{
int ret = 0
while( ! (ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst)
{
++src;
++dst;
}
if ( ret < 0 )
ret = -1
else if ( ret > 0 )
ret = 1
return( ret );
}
3,
求
1000
!的未尾有几个< br>0
(用素数相乘的方法来做,如
72=2*2*2*3*3
)
;
求出
1->1000
里
,
能被
5
整除的 数的个数
n1,
能被
25
整除的数的个数
n2,
能被
125
整除的数
的个数
n3,
能被
625
整除的数的个数
n4.
1000!
末尾的零的个数
=n1+n2+n3+n4;
#include
#define NUM 1000
int find5(int num){
int ret=0;
while(num%5==0){
num/=5;
ret++;
}
return ret;
}
int main(){
int result=0;
int i;
for(i=5;i<=NUM;i+=5)
{
result+=find5(i);
}
printf(
return 0;
}
1.
有双向循环链表结点定义为:
struct node
{ int data;
struct node *front,*next;
};
有两个双向循环链表
A
,
B
, 知道其头指针为:
pHeadA,pHeadB
,请写一函数将两链表中
data值相同的结点删除
BOOL DeteleNode(Node *pHeader, DataType Value)
{
if (pHeader == NULL) return;
BOOL bRet = 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)
{
pNode->next->front = pNode->front;
}
pNode->front->next = pNode->next;
}
Node *pNextNode = pNode->next;
delete pNode;
pNode = pNextNode;
bRet = TRUE;
//
不要
break
或
return,
删除所有
}
else
{
pNode = pNode->next;
}
}
return bRet;
}
void DE(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;
pHeadA->front = NULL;
}
else
{
pNode->front->next = pNode->next;
if (pNode->next != NULL)
{
pNode->next->front = pNode->front;
}
}
Node *pNextNode = pNode->next;
delete pNode;
pNode = pNextNode;
}
else
{
pNode = pNode->next;
}
}
}
2.
编程实现:找出两个字符串中最大公共子字符串
,
如
的最大子串为
int GetCommon(char *s1, char *s2, char **r1, char **r2)
{
int len1 = strlen(s1);
int len2 = strlen(s2);
int maxlen = 0;
for(int i = 0; i < len1; i++)
{
for(int j = 0; j < len2; j++)
{
if(s1[i] == s2[j])
{
int as = i, bs = j, count = 1;
while(as + 1 < len1 && bs + 1 < len2 && s1[++as] == s2[++bs])
count++;
if(count > maxlen)
{
maxlen = count;
*r1 = s1 + i;
*r2 = s2 + j;
}
}
}
劳动模范事迹材料-欣然自得
劳动模范事迹材料-欣然自得
劳动模范事迹材料-欣然自得
劳动模范事迹材料-欣然自得
劳动模范事迹材料-欣然自得
劳动模范事迹材料-欣然自得
劳动模范事迹材料-欣然自得
劳动模范事迹材料-欣然自得
本文更新与2021-01-21 03:58,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/542227.html
-
上一篇:英语教师面试问题经典合集
下一篇:HR面试五大经典问题和问答