开发平台(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杯或肯德基、麦当劳套餐一份作为答谢。