- 相關推薦
c/c++某大公司的兩道筆試題
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<1)
{
printf("n doen't 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 < b->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++某大公司的兩道筆試題】相關文章:
C++筆試題03-25
C++ 筆試題08-09
Sony C++筆試題02-11
普天C++筆試題02-18
基礎C++/C語言筆試題分享11-21
聚網科技C++筆試題07-20
普天C++筆試題面試技巧11-06
群碩筆試題Java和C++、C#11-21
C++工程師筆試題目11-25