c语言笔试面试题目及答案,2019腾讯校园招聘C语言笔试题和面试题答案

7. 压缩字符串

例如字串”aaabbbbccccc”,转换成相邻字符+个数的形式压缩,成为”a3b4c5”。

(如果有10个数相同)

假设需要考虑解压缩

char *MergeString(const char * ch)

{

char *s=(char *)malloc(sizeof(ch));

if(s!=NULL)

{

int len=strlen(ch), i=0,j=0,k=0;

for(;i

{

int num=0;

while(ch[j]==ch[i]) j++,num++;

s[k++]=ch[i];

sprintf(s+k,"%d",num);

k=strlen(s);

}

}

return s;

}

8. 如何判断一个单向链表是否有环。

int ISCircle(pListNode head)

{

pListNode p1=head;

p1=p1->m_pNext;

while(p1!=NULL)

{

if(p1==head) return 1;

else p1=p1->m_pNext;

}

return 0;

}

9. 判断一个字符串是否对称。

aabbaa , efffe返回true

aabac返回false

int SymmetricString( const char *ch)

{

int len=strlen(ch);

int i=0,j=len-1;

if(len%2!=0) return 0;

for(i=0,j=len-1;i<=len/2;i++,j--)

{

if(ch[i]!=ch[j]) return 0;

}

return 1;

}

10. 判断一个字符串是否是另一个字符串的字串

int next[20];

void get_next(const char* T,int next[])

{

int i=0,j=-1;next[0]=-1;

int len=strlen(T);

while(i

{

if(j==-1||T[i]==T[j]) {++i;++j;next[i]=j;}

else j=next[j];

}

}

int index_KMP(const char * S,const char * T)

{

int i=0,j=0;

get_next(T,next);

int lens=strlen(S),lent=strlen(T);

while(i

if(j==-1 ||S[i]==T[j]){++i;++j;}

else j=next[j]; }

if(j>=lent) return i-lent;

else return -1;

}

链表的定义,栈的定义:

typedef struct stack

{

int top;

int space[MAXLEN+1];

}Stack;

int push(Stack *s,int num)

{

if(s->top>=sizeof(s->space)/sizeof(int)) return -1;//Error

s->space[s->top++]=num;

return num;

}

int pop(Stack *s)

{

if(s->top<0) return -1;

return s->space[--s->top];

}

int IsEmpty(Stack *s)

{

return s->top==0;

}

typedef struct ListNode

{

int m_nKey;

struct ListNode *m_pNext;

}ListNode,*pListNode;

pListNode CreateList()

{

srand((unsigned long)time(NULL));

pListNode head,p1,p2;

head=(pListNode)malloc(sizeof(ListNode));

p1=head;p2=p1;

int i=MAXLEN;

while(i--){

p2=(pListNode)malloc(sizeof(ListNode));

p2->m_nKey= rand()*rand()%(MAXLEN*rand());

p1->m_pNext=p2;

p1=p2;

}

p2->m_pNext=NULL;

return head;

}

void PrintList(pListNode head)

{

pListNode p=head;

do{

printf("%d/n",p->m_nKey);

p=p->m_pNext;

}while(p!=NULL);更多热门的笔试题目分享:

湖南广电笔试真题

2015华邦软件工程师笔试题

光大期货笔试真题

马士基笔试真题笔试题型

1 2

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值