[問題] 關於幾個面試的問題...
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
由於剛退伍,腦袋已經轉不過來,題目一共有六題,
解完四題後,已經越來越滿身冷汗....
之前實習的考試能寫四題我已經很開心了,
但是這次面試考官給了點時間,所以想把他寫得完整一點...
請教版上各位前輩給予指教,
小弟萬分感謝!!!
1.
下面程式是想做甚麼判定?
bool test(int X)
{
return (!(X&(X-1)))
}
2. 優化下段程式,並解釋理由:
// Optimze the following code in ANY directions.
// HINT: try more directions.
// Such as code generality to different compilers, memory access overhead,
// memory use, calculating overhead, code efficiency...etc.
#define WHITE 255
#deifne BLACK 0
#deinfe THRESHOLD 20
#define WINDOW_HEIGHT 5
#define BOOL int
#define TRUE 1
#define FALSE 0
BOOL funtionFromRight(int score, int width, byte * * image, int xi, int yi)
{
BOOL b;
int leftBound = 2;
for(b=xi-1; b > leftBound && b < width-2 ; b=b-1)
{
if(image[yi][b] == WHITE && image[yi][b+1] == BLACK)
{
int isVertical=0;
for(int c = WINDOW_HEIGHT*(-1); c <= WINDOW_HEIGHT ; c++)
{
isVertical+=image[yi+c][b_next];
isVertical+=image[yi+c][b];
}
if(isVertical <= THRESHOLD && score > 200)
return TRUE;
}
if(image[yi] [b] == BLACK)
break;
}
return FALSE;
}
BOOL funtionFromLeft(int score, int width, byte * * image, int xi, int yi)
{
BOOL b;
int leftBound = 2;
for(b=xi+1; b > leftBound && b < width-2 ; b=b+1)
{
if(image[yi][b] == WHITE && image[yi][b+1] == BLACK)
{
int isVertical=0;
for(int c = WINDOW_HEIGHT*(-1); c <= WINDOW_HEIGHT ; c++)
{
isVertical+=image[yi+c][b_next];
isVertical+=image[yi+c][b];
}
if(isVertical <= THRESHOLD && score > 200)
return TRUE;
}
if(image[yi][b] == BLACK)
break;
}
return FALSE;
}
小弟知道這樣是不勞而獲,但是請給年輕人一個機會吧<(_ _)>
當了一年的笨蛋,回過頭來真的很多都忘光了....
前天收到考題,我已經在電腦前面坐了17個小時了....(包含廁所)
埋在裡面這麼久,明天就要交卷了...
所以在這邊拜託各位前輩了.....
小弟願奉上雞排1份、COCO珍奶1杯或肯德基、麥當勞套餐一份作為答謝。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.44.197.195
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1415559298.A.B71.html
※ 編輯: MarkHero (114.44.197.195), 11/10/2014 02:56:43
※ 編輯: MarkHero (114.44.197.195), 11/10/2014 03:02:13
推
11/10 03:25, , 1F
11/10 03:25, 1F
→
11/10 03:35, , 2F
11/10 03:35, 2F
→
11/10 03:35, , 3F
11/10 03:35, 3F
感謝前輩指點,但相信我,我已經花了整整18小時在思考這些試題,
考卷不會是別人寫的,我會整合各位的意見,而原本的六個試題,
我已經絞盡腦汁寫了四題,我也不希望這樣,但是時間壓力讓我不得不上來求助,
十分抱歉讓前輩觀感不佳,我只希望我未來能更努力...
※ 編輯: MarkHero (114.44.197.195), 11/10/2014 03:58:26
→
11/10 04:07, , 4F
11/10 04:07, 4F
→
11/10 04:09, , 5F
11/10 04:09, 5F
→
11/10 04:10, , 6F
11/10 04:10, 6F
→
11/10 04:11, , 7F
11/10 04:11, 7F
→
11/10 04:12, , 8F
11/10 04:12, 8F
小弟的確已經從GOOGLE上取得第一題的答案,但不確定是否是判斷X是否為2的n次方,
求好心切下才將此提納入發問中,第二題我真的一點頭緒都沒有,
code的優化我真的沒有特別研究過,感謝前輩指點,小弟再下去想想,
抱歉造成您觀感不佳,其實不是我一點說明都沒有,而是這題我真的完全找不到頭緒。
※ 編輯: MarkHero (114.44.197.195), 11/10/2014 04:16:42
推
11/10 10:55, , 9F
11/10 10:55, 9F
→
11/10 10:56, , 10F
11/10 10:56, 10F
→
11/10 11:13, , 11F
11/10 11:13, 11F
推
11/10 13:27, , 12F
11/10 13:27, 12F
→
11/10 13:28, , 13F
11/10 13:28, 13F
→
11/10 16:26, , 14F
11/10 16:26, 14F
→
11/10 16:26, , 15F
11/10 16:26, 15F
→
11/10 16:27, , 16F
11/10 16:27, 16F
→
11/10 16:27, , 17F
11/10 16:27, 17F
→
11/10 16:28, , 18F
11/10 16:28, 18F
→
11/10 16:28, , 19F
11/10 16:28, 19F
推
11/10 16:34, , 20F
11/10 16:34, 20F
推
11/10 18:22, , 21F
11/10 18:22, 21F
→
11/10 18:22, , 22F
11/10 18:22, 22F
推
11/10 19:51, , 23F
11/10 19:51, 23F
→
11/10 19:53, , 24F
11/10 19:53, 24F
→
11/10 19:58, , 25F
11/10 19:58, 25F
→
11/10 20:02, , 26F
11/10 20:02, 26F
→
11/10 20:04, , 27F
11/10 20:04, 27F
→
11/10 21:18, , 28F
11/10 21:18, 28F
→
11/10 21:19, , 29F
11/10 21:19, 29F
→
11/10 23:29, , 30F
11/10 23:29, 30F