c/c++某大公司的兩道筆試題
1.一群人圍成一圈,123的報(bào)數(shù),報(bào)3者出列,求最后一個(gè)人,
c/c++某大公司的兩道筆試題
。2.利用鏈表實(shí)現(xiàn)將兩個(gè)有序隊(duì)列A和B合并到有序隊(duì)列H中,不準(zhǔn)增加其他空間。
請(qǐng)?zhí)峁┤稽c(diǎn)的程序
第一題:
// 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;
}
【c/c++某大公司的兩道筆試題】相關(guān)文章:
1.C/C++筆試題
2.C++筆試題
7.普天C++筆試題
8.C++面試題