网易2011笔试题详解
来源:互联网 发布:评标专家库软件 编辑:程序博客网 时间:2024/06/07 02:58
http://blog.csdn.net/silangquan/article/details/18051675
网上弄到的一份题,不是很完整,边猜边做。
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.
如果给出结构体,考虑到字节对齐的话就要另外考虑了。
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才可以.
- 网易2011笔试题详解
- 网易笔试编程题详解
- 剑指XX游戏(二) - 网易2011笔试题详解
- 网易2013校园招聘笔试题详解
- 网易2013校园招聘笔试题详解
- 网易笔试题,推箱子详解
- 2011 网易公司笔试题
- 五道网易笔试题2011
- 2011网易校园招聘笔试题
- 网易2011年笔试
- 网易一道笔试题!
- 网易笔试题
- 网易笔试题
- 网易笔试题一道
- 网易一道笔试题!
- 网易笔试题
- 网易笔试题
- 2012网易笔试题
- 特种浓缩分离:带式压榨过滤机的特点
- UVA - 568 Just the Facts
- 类成员函数作为多线程的入口函数的实现方法
- Python中用zlib.decompress出错:error: Error -3 while decompressing data: incorrect header check
- hdu 1099
- 网易2011笔试题详解
- jni问题摘记
- 查看CPU信息
- 如何判断手机是否支持OTG
- Android中Animation的使用总结
- OC-内存管理之autorelease和release
- iOS中多任务
- WPF打开文件
- PA的设置,PA功率的设置