Posted in 面试题 onFebruary 02, 2014
1.一群人围成一圈,123的报数,报3者出列,求最后一个人。
2.利用链表实现将两个有序队列A和B合并到有序队列H中,不准增加其他空间。
请提供全一点的程序
第一题:
// kickout.cpp : Defines the entry point for the console application.
//
#include “stdafx.h”
#include “malloc.h”
#include “stdio.h”
int main()
{
int m,n;
int kickouts = 0;
int *p = NULL;
int i ,j;
i=j=0;
printf(“Please input m,n:”);
scanf(“%d,%d”,&m,&n);
while(n {
printf("n doent less 0 , retry n:");
scanf("%d",&n);
}
p=(int*)malloc(m*sizeof(int));
for(i=0;i
p[i]=1;
i = 0;
while(1)
{
i = i%m;
if(p[i++]) j++;
if(j == n)
{
p[i-1]=0;
j = 0;
kickouts++;
}
if(kickouts == m-1)
break;
}
for(i = 0;i
if(p[i]) printf("%d\n",i+1);
return 0;
}
2、升序还是降序?
以升序为例:
while(a != NULL && b!= NULL)
{
if (a->data data)
{
h->data = a->data;
a = a->next;
}
else if (a->data == b->data)
{
h->data = a->data;
a = a->next;
b = b->next;
}
else
{
h->data = b->data;
b = b->next
}
h = h->next;
}
if (a == NULL)
{
while (b != NULL)
{
h->data = b->data;
h = h->next;
b = b->next;
}
}
else
{
while(a != NULL)
{
h->data = a->next;
h = h->next;
a = a->next;
}
}
2.利用链表实现将两个有序队列A和B合并到有序队列H中,不准增加其他空间。
请提供全一点的程序
第一题:
// kickout.cpp : Defines the entry point for the console application.
//
#include “stdafx.h”
#include “malloc.h”
#include “stdio.h”
int main()
{
int m,n;
int kickouts = 0;
int *p = NULL;
int i ,j;
i=j=0;
printf(“Please input m,n:”);
scanf(“%d,%d”,&m,&n);
while(n {
printf("n doent less 0 , retry n:");
scanf("%d",&n);
}
p=(int*)malloc(m*sizeof(int));
for(i=0;i
p[i]=1;
i = 0;
while(1)
{
i = i%m;
if(p[i++]) j++;
if(j == n)
{
p[i-1]=0;
j = 0;
kickouts++;
}
if(kickouts == m-1)
break;
}
for(i = 0;i
if(p[i]) printf("%d\n",i+1);
return 0;
}
2、升序还是降序?
以升序为例:
while(a != NULL && b!= NULL)
{
if (a->data data)
{
h->data = a->data;
a = a->next;
}
else if (a->data == b->data)
{
h->data = a->data;
a = a->next;
b = b->next;
}
else
{
h->data = b->data;
b = b->next
}
h = h->next;
}
if (a == NULL)
{
while (b != NULL)
{
h->data = b->data;
h = h->next;
b = b->next;
}
}
else
{
while(a != NULL)
{
h->data = a->next;
h = h->next;
a = a->next;
}
}
c/c++某大公司的两道笔试题
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Tags in this post...
Reply on: @reply_date@
@reply_contents@