温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

剑指XX游戏(二) - 网易2011笔试题详解

发布时间:2020-07-06 21:45:25 来源:网络 阅读:438 作者:拳四郎 栏目:开发技术

网上弄到的一份题,不是很完整,边猜边做。


1.写出运行结果

char array[] = “abcde”; char* s = array;

cout<<sizeof(array)<<strlen(array)<<sizeof(s)<<strlen(s);


6585


2.什么是用户级线程和内核级线程?区别。

内核级线程:
(1)线程的创建、撤销和切换等,都需要内核直接实现,即内核了解每一个作为可调度实体的线程。
(2)这些线程可以在全系统内进行资源的竞争。
(3)内核空间内为每一个内核支持线程设置了一个线程控制块(TCB),内核根据该控制块,感知线程的存在,并进行控制。
在一定程度上类似于进程,只是创建、调度的开销要比进程小。有的统计是1:10
用户级线程:
(1)用户级线程仅存在于用户空间。——>对比内核(3)
(2)内核并不能看到用户线程。——>重要的区别

(3)内核资源的分配仍然是按照进程进行分配的;各个用户线程只能在进程内进行资源竞争。


3.从C++文件到生成exe 文件经过哪三个步骤?

预编译,编译优化,汇编,链接


4.有个二维数组 A(6*8),每个元素占 6 字节,起始地址为 1000,请问最后一个元素 A[5][7]的起始地址为??? 数组A占内存大小为??? 假设以行优先,则A[1][4]起始地址为???

1)1000 + 6*6*8 - 8 = 11282; 2)6*6*8=288; 3)A[1][4]位置为5行2列,1000+6*(8*1+4) = 1272.


如果给出结构体,考虑到字节对齐的话就要另外考虑了。

剑指XX游戏(二) - 网易2011笔试题详解


5.用C语言把双向链表中的两个结点交换位置,考虑各种边界问题。 

考虑三种情况:第一个结点在头,第一个结点在中间,第一个结点在尾巴。

struct Node{       Node* prev;          Node* next;          void* data;      };      struct LinkedList{       Node*    head;       Node*    tail;       Node*    cur;       int      size;   };   bool exchange(LinkedList* list,Node *node1,Node *node2)  {      if(node1== NULL || node2==NULL)      return false;     Node *p,*q; 	//node1 on the front     if(list->head->next == node1)     {     	//node2 on the last     	if(list->tail->next == node2)     	{     		p = node2->prev;     		//Cope with node2     		list->head->next = node2;     		node2->prev = list->head;     		node2->next = node1->next;     		node2->next->pre = node2;     		//Cope with node1     		list->tail->prev = node1;     		node1->next = list->tail;     		node1->prev = p;     		p->next = node1;     		return true;     	}     	//node2 not on the last     	else     	{     		p = node2->prev;     		q = node2->next;     		//Cope with node2     		list->head->next = node2;     		node2->prev = list->head;     		node2->next = node1->next;     		node2->next->prev = node2;     		//Cope with node1     		p->next = node1;     		node1->prev = p;     		node1->next = q;     		q->prev = node1;     		return true;     	} 		     }     //node1 on the last     else if(list->tail->next == node1)     {     	//node2 on the front     	if(list->head->next == node2)     	{ 			p = node1->prev;     		//Cope with node1     		list->head->next = node1;     		node1->prev = list->head;     		node1->next = node2->next;     		node1->next->prev = node1;     		//Cope with node2     		list->tail->prev = node2;     		node2->next = list->tail;     		node2->prev = p;     		p->next = node2;     		return true;     	}     	//node2 not on the front     	else     	{     		p = node2->prev;     		q = node2->next;     		//Cope with node2     		list->tail->next = node2;     		node2->prev = list->tail;     		node2->next = node1->next;     		node2->next->prev = node2;     		//Cope with node1     		p->next = node1;     		node1->prev = p;     		node1->next = q;     		q->prev = node1;     		return true;     	}     }     //node1 on the middle     else     {     	//node2 on the front     	if(list->head->next == node2)     	{     		p = node1->prev;     		q = node1->next;     		node1->prev = list->head;     		list->head->next = node1;     		node1->next = node2->next;     		node2->next->prev = node1;     		     		node2->prev = p;     		p->next = node2;     		node2->next = q;     		q->prev = node2;     	}     	//node2 on the last     	else if(list->tail->next == node2)     	{     		p = node1->prev;     		q = node1->next;     		node1->prev = node2->prev;     		node2->prev->next = node1;     		node1->next = list->tail;     		list->tail->prev = node1;     		     		node2->prev = p;     		p->next = node2;     		node2->next = q;     		q->prev = node2;     	}     	//both in the middle     	else     	{     		p = node2->prev;     		q = node2->next;     		//Cope with node2     		node2->prev = node1->prev;     		node1->prev->next = node2;     		node2->next = node1->next;     		node1->next->prev = node2;     		//Cope with node1     		p->next = node1;     		node1->prev = p;     		node1->next = q;     		q->prev = node1;     		return true;     	}     }  } 




6.*.dll,*.lib,*.exe 文件分别是什么,有什么区别?

lib是静态的库文件,dll是动态的库文件。
所谓静态就是link的时候把里面需要的东西抽取出来安排到你的exe文件中,以后运行exe的时候不再需要lib。
所谓动态就是exe运行的时候依赖于dll里面提供的功能,没有这个dll,exe无法运 行。

lib, dll, exe都算是最终的目标文件,是最终产物。而c/c++属于源代码。源代码和最终 目标文件中过渡的就是中间代码obj,实际上之所以需要中间代码,是你不可能一次得到目 标文件。比如说一个exe需要很多的cpp文件生成。而编译器一次只能编译一个cpp文件。这 样编译器编译好一个cpp以后会将其编译成obj,当所有必须要的cpp都编译成obj以后,再统 一link成所需要的exe,应该说缺少任意一个obj都会导致exe的链接失败.



7.附加题(20):使用八叉树算法把24位真彩色转化成 256色。24位真彩色包括 R,G,B颜色,每种颜色8 位。

         在计算机中像素的计算单位一般是二进制的,256色,即2的8次方,因此我们也把256×××形叫做8位图;16位图,它可以表达2的16次方即65536种颜色;还有24位彩×××,可以表达16,777,216种颜色。

         算法参考:http://blog.csdn.net/zuzubo/article/details/1597985



8.有 11 盆花,围成一圈,要求每次组合时,每盆花相邻的两盆花与上次不同,请问有多少排列方法? 

待解答。


9.2 只宠物合成,1只有 5技能,1 只有4 技能,每个技能有 a%概率遗传,请问刚好有7 个技能遗传成功的概率是?

只有

第一只5个技能 + 第二只2个技能:(a%)^7*C(4,2)

第一只4个技能 + 第二只3个技能:(a%)^7*C(5,4)*C(4,3)

第一只3个技能 + 第二只4个技能:(a%)^7*C(5,3)

加起来就可以了。


10.输出结果为?

#include <iostream> using namespace std; class A	 { public: 	A(){cout<<"1";} 	A(A &a){cout <<"2";} 	virtual ~A() {cout<<"3";} };  class B:public A { public: 	B(){cout<<"4";} 	B(B &b){cout<<"5";} 	~B(){cout<<"6";} };  int main() {     A* pa = new B(); 	delete pa; 	return 0; }


1463

子类构造之前首先调用基类的构造函数,然后是子类的构造函数,析构的时候相反,注意基类的析构函数声明为virtual才可以.




向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI