读书人

今天去Gameloft去面试,以下就是面试的

发布时间: 2012-02-12 17:16:34 作者: rapoo

今天去Gameloft去面试,以下就是面试的题目和一些答案了.
一共是8道题目
1.哪些操作会隐式调用C++的拷贝构造函数?
貌似答案是B和C,是一道选择题,
2.数据结构定义:通道和墙组成的迷宫
这个可以写一个矩阵了,比如 a[x][y]
然后用0表示墙,1表示可以通过
3.一个16x16像素的date画在一个坐标为x,y的屏幕上,屏幕的像素是Wscreen和Hscreen,函数改错.

4.单链表结构定义:节点存储一个整型数,给代码。合并二个已经按照该整型数从小到大排好序的链表,合并后链表也是同样排序好的。
typedef struct p
{
int date;
struct p *next;
}node;
Node* uniteList(Node* first,Node*second)
{
Node*head=NULL;
Node*cur=NULL;
Node*temp=NULL;
while (first&&second)
{
if (first-> key <second-> key)
{
temp=first;
first=first-> next;
}
else
{
temp=second;
second=second-> next;
}

if (head==NULL)
{
cur=temp;
head=cur;
}
else
{
cur-> next=temp;
cur=temp
}

}
if (first==NULL)
{
temp=second;
}
else
temp=first;
while (temp)
{
cur-> next=temp;
temp=temp-> next;
}
cur-> next=NULL;
return head;
}
5.设计一个函数,找出水仙花数,水仙花数的定义153=1^3+5^3+3^3
貌似要写一个可扩展的水仙花数的程序了...
6.设计一个函数,找出一个32位的整形二进制数中的1的个数,尽量不要使用逐位比较.

7.回文,用递归的查找回文了,填程序.

8.写出一个函数用来判断一个点到一个平面的关系。用一个点和法向量来表示平面。输入一个点和一个面,返回该点在面的前面,后面,还是在这个面上。
bool loc(Point pt,Plain pn)
{
bool res = static_cast <bool> (pn.getl*(po.getx-pn.geta)+pn.getm(po.gety-pn.getb)+pn.getn(po.getz-pn.getc))
return res;
}
大家可以来试试看了,能做出5,6题的给分~~~~.

[解决办法]
6.设计一个函数,找出一个32位的整形二进制数中的1的个数,尽量不要使用逐位比较.

有一本书叫《Hacker 's Delight》,里面讲了很多这种雕虫小技。下面的函数是从书里抄来的:

int pop(unsigned x) {
x = x - ((x > > 1) & 0x55555555);
x = (x & 0x33333333) + ((x > > 2) & 0x33333333);
x = (x + (x > > 4)) & 0x0F0F0F0F;
x = x + (x > > 8);
x = x + (x > > 16);
return x & 0x0000003F;
}

[解决办法]
5.设计一个函数,找出水仙花数,水仙花数的定义153=1^3+5^3+3^3
main()
{
int i,j,k,n;
cout < < " 'water flower 'number is: ");
 for(n=100;n <1000;n++)
 {
  i=n/100;/*分解出百位*/
  j=n/10%10;/*分解出十位*/
  k=n%10;/*分解出个位*/
  if(i*100+j*10+k==i*i*i+j*j*j+k*k*k)
   {
   cout < <n;
   }
 }
printf( "\n ");
}
[解决办法]
//程序: arm_number.cpp
//功能: 求水仙花数(是一个n(n> =3)位数字的数,它等于每位数字的n次幂的和)

#include <iostream.h>
#include <math.h>
#include <time.h>

//函数声明
int arm_number(int max); //此函数的功能是求小于max的所有水仙花数

int main()
{
int max,second;
time_t t;
cout < < "input the max number: ";
cin> > max;

second=time(&t);
arm_number(max);
second=time(&t)-second;
cout < < "The total times is: " < <second < < '\n ';

return 0;
}

//函数定义
int arm_number(int max)


{
int num,radix=10,x,y,time=0;
for(num=100;num <=max;num++){ //从100到max逐个搜索符合条件的数

int n=0,power=1,total=0;
while(power <=num){
power=power*radix;
n++; //统计此数是几位数
time++;
}

while(power> =10){
x=(num%power)/(power/10); //从高位到低位逐位求值
y=n; //y为n次幂
total=total+int(pow(x,y)); //求每位数字的n次幂的和
power=power/10;
time++;
}
if(total==num) cout < < "The arm number is: " < <num < < '\n '; //如果此数符合水仙数则输出
}
cout < < "The times of computed is: " < <time < < '\n '; //统计计算机的运算次数
return 0;
}
转自:http://topic.csdn.net/t/20010708/00/185687.html

读书人网 >C++

热点推荐