一份软件工程师的面试试题


Posted in 面试题 onFebruary 01, 2016
1、现有1000个苹果,10个盒子,问各个盒子内应该分别放入多少个苹果,才能使得用户要买任意1至1000之间的一个苹果数,都可以给他(卖的时候是整个盒子卖,不能拆盒子的包装)。
2、请仔细阅读下面的资料:
1)材料一:CArray
template class CArray : public CObject
Parameters:
TYPE
Template parameter specifying the type of objects stored in the array.
TYPE is a parameter that is returned by CArray.
ARG_TYPE
Template parameter specifying the argument type used to access objects stored in the array.
Often a reference to TYPE. ARG_TYPE is a parameter that is passed to CArray.
Remarks:
The CArray class supports arrays that are are similar to C arrays, but can dynamically shrink and grow as necessary.
Array indexes always start at position 0. You can decide whether to fix the upper bound or allow the array to expand when you add elements past the current bound. Memory is allocated contiguously to the upper bound, even if some elements are null.
int CArray::Add (ARG_TYPE newElement);
Return Value:
The index of the added element.
Parameters:
ARG_TYPE
Template parameter specifying the type of arguments referencing elements in this array.
newElement
The element to be added to this array.
TYPE& CArray::operator [] (int nIndex);
Parameters:
TYPE
Template parameter specifying the type of elements in this array.
nIndex
Index of the element to be accessed.
Remarks:
Returns the array reference of element at the specified index.
2)材料二:CList
templateclass CList : public CObject
Parameters:
TYPE
Type of object stored in the list.
ARG_TYPE
Type used to reference objects stored in the list. Can be a reference.
Remarks:
The CList class supports ordered lists of nonunique objects accessible sequentially or by value.
CList lists behave like doubly-linked lists.
void CList::AddTail(ARG_TYPE newElement);
Parameters:
ARG_TYPE
Template parameter specifying the type of the list element (can be a reference).
newElement
The element to be added to this list.
Remarks:
Adds a new element or list of elements to the tail of this list. The list can be empty before the operation.
3)材料三: realloc
realloc
Reallocate memory blocks.
void *realloc(void *memblock, size_t size);
Return Value:
The return value points to a storage space that is guaranteed to be suitably aligned for storage of any type of object. To get a pointer to a type other than void, use a type cast on the return value.
Remarks:
The size argument gives the new size of the block, in bytes. The contents of the block are unchanged up to the shorter of the new and old sizes, although the new block can be in a different location. Because the new block can be in a new memory location, the pointer returned by realloc is not guaranteed to be the pointer passed through the memblock argument.
4)请指出下面这段代码可能会出现的问题
CList g_ValueList;
CArray g_ValuePool;
void AddNewValue (const VARIANT& newValue)
{
g_ValueList.AddTail(&g_ValuePool[g_ValuePool.Add(newValue)]);
}
3、有一无符号整型数组,大小为10, 初始的数值随机,但在[0, 99]之间。请用C语言写一个过滤程序,令数组内的数据互不相等。
说明:
1.若数组内有相等的数据,可令某一数值加1或减1作出偏移,直至不等为止。
2.数组内的数据只能在[0, 99]之间。
3.保持数组内的数据位置不变,即对应下标不变。
4.按要求编写以下函数。
功能:将给定缓冲区中的#字符移到字符串尾部
函数名称:ChangeToTail
入口参数:pSZ指向缓冲区的指针, nSize缓冲区长度
出口:pSZ所指缓冲区中的#字符被移到缓冲区尾部
返回值:在出口缓冲区中第一个#的位置,若缓冲区中无#字符则返回-1
说明:如传入#W#W#W#WW#, 10 则传出时应转换为WWWWW#####并且返回值为5
int ChangeToTail(BYTE* pSZ, UINT nSize)
{
// Todo:请在此加入您的代码
}
5、在金山,有一个非常经典有趣的游戏,称为杀人游戏。此游戏角色有:好人(m人)、坏人(n人)、村长(1人)、裁判(1人)。角色采用一定方式(如:抓阄)分配。村长、裁判两个角色是公开的,而好人、坏人两个角色则只要裁判和本人心知肚明。其玩法如下:
游戏开始了,裁判说:“天黑了”,这是所有其他角色都低头闭上眼睛(不准作弊!)。然后裁判说:“坏人开始活动”,此时坏人抬起头,并相互商议,杀死一个好人。然后裁判说:“天亮了”,此时所有人抬头,被杀死的那个好人宣布出局。剩下的人在村长的主持下,开始判断杀人凶手。每个人可以根据各人的表情反应,判断并提议杀死自己心目中的坏人。不过最终的裁决权属于村长,综合大家的意见杀死一人。此时裁判宣布此人出局。游戏进入下一轮,由天黑到天亮,再有2人出局,如此反复,直到最后好人先被全部杀死,则游戏结束,“邪恶”的一方战胜了“正义”的一方;而另一个结局则是在大家以及村长的英明决断下,坏人被全部杀死,则“正义”的一方战胜了“邪恶”的一方。
现在,我们的问题是,请写出你的思路,并编写一个C/C++语言程序,求出:在坏人有两个(n = 2)的情况下,需要多少个好人(m = ?),才能够使这个游戏比较公平,也就是说,从概率上说,“正义”的一方与“邪恶”的一方胜利的几率最接近于50%。
(此题与下面一题选做一道)
6、在以上的杀人游戏中,还有一个玩法,就是取消村长这个角色,“天亮”后剩余的人每个人投票列出自己心目中最怀疑的2个人,以此决定让谁出局。试问,在此玩法下,上面的问题又何解?
7.C++程序设计
1).写出以下程序的运行结果:
#include
class Base
{
public:
Base()
{
cout }
Base(const Base &theBase)
{
cout }
~Base()
{
cout }
void Open()
{
OnOpen();
}
private:
virtual void OnOpen() = 0;
};
class Derived : public Base
{
public:
Derived()
{
cout }
Derived(const Derived &theDerived)
{
cout }
~Derived()
{
cout }
private:
virtual void OnOpen()
{
//这里可能抛出异常
}
};
Base *CreateInstance()
{
return new Derived();
}
int main()
{
Base *pBase = ::CreateInstance();
if (pBase)
{
pBase->Open();
delete pBase;
}
return 0;
}
2).在1)中,类Base和类Derived的实现有没有问题?如果有,如何修改?
3).说明1)中类Base的Open函数和OnOpen函数的设计目的和意义。
4).使用STL技术修改main()函数中的代码,使之成为异常安全的。

1、现有1000个苹果,10个盒子,问各个盒子内应该分别放入多少个苹果,才能使得用户要买任意1至1000之间的一个苹果数,都可以给他(卖的时候是整个盒子卖,不能拆盒子的包装)。

2、请仔细阅读下面的资料:

1)材料一:CArray

template class CArray : public CObject

Parameters:

TYPE

Template parameter specifying the type of objects stored in the array.

TYPE is a parameter that is returned by CArray.

ARG_TYPE

Template parameter specifying the argument type used to access objects stored in the array.

Often a reference to TYPE. ARG_TYPE is a parameter that is passed to CArray.

Remarks:

The CArray class supports arrays that are are similar to C arrays, but can dynamically shrink and grow as necessary.

Array indexes always start at position 0. You can decide whether to fix the upper bound or allow the array to expand when you add elements past the current bound. Memory is allocated contiguously to the upper bound, even if some elements are null.

int CArray::Add (ARG_TYPE newElement);

Return Value:

The index of the added element.

Parameters:

ARG_TYPE

Template parameter specifying the type of arguments referencing elements in this array.

newElement

The element to be added to this array.

TYPE& CArray::operator [] (int nIndex);

Parameters:

TYPE

Template parameter specifying the type of elements in this array.

nIndex

Index of the element to be accessed.

Remarks:

Returns the array reference of element at the specified index.

2)材料二:CList

templateclass CList : public CObject

Parameters:

TYPE

Type of object stored in the list.

ARG_TYPE

Type used to reference objects stored in the list. Can be a reference.

Remarks:

The CList class supports ordered lists of nonunique objects accessible sequentially or by value.

CList lists behave like doubly-linked lists.

void CList::AddTail(ARG_TYPE newElement);

Parameters:

ARG_TYPE

Template parameter specifying the type of the list element (can be a reference).

newElement

The element to be added to this list.

Remarks:

Adds a new element or list of elements to the tail of this list. The list can be empty before the operation.

3)材料三: realloc

realloc

Reallocate memory blocks.

void *realloc(void *memblock, size_t size);

Return Value:

The return value points to a storage space that is guaranteed to be suitably aligned for storage of any type of object. To get a pointer to a type other than void, use a type cast on the return value.

Remarks:

The size argument gives the new size of the block, in bytes. The contents of the block are unchanged up to the shorter of the new and old sizes, although the new block can be in a different location. Because the new block can be in a new memory location, the pointer returned by realloc is not guaranteed to be the pointer passed through the memblock argument.

4)请指出下面这段代码可能会出现的问题

CList g_ValueList;

CArray g_ValuePool;

void AddNewValue (const VARIANT& newValue)

{

g_ValueList.AddTail(&g_ValuePool[g_ValuePool.Add(newValue)]);

}

3、有一无符号整型数组,大小为10, 初始的数值随机,但在[0, 99]之间。请用C语言写一个过滤程序,令数组内的数据互不相等。

说明:

1.若数组内有相等的数据,可令某一数值加1或减1作出偏移,直至不等为止。

2.数组内的数据只能在[0, 99]之间。

3.保持数组内的数据位置不变,即对应下标不变。

4、 按要求编写以下函数。

功能:将给定缓冲区中的#字符移到字符串尾部

函数名称:ChangeToTail

入口参数:pSZ指向缓冲区的指针, nSize缓冲区长度

出口:pSZ所指缓冲区中的#字符被移到缓冲区尾部

返回值:在出口缓冲区中第一个#的位置,若缓冲区中无#字符则返回-1

说明:如传入#W#W#W#WW#, 10 则传出时应转换为WWWWW#####并且返回值为5

int ChangeToTail(BYTE* pSZ, UINT nSize)

{

// Todo:请在此加入您的代码

}

5、在金山,有一个非常经典有趣的游戏,称为杀人游戏。此游戏角色有:好人(m人)、坏人(n人)、村长(1人)、裁判(1人)。角色采用一定方式(如:抓阄)分配。村长、裁判两个角色是公开的,而好人、坏人两个角色则只要裁判和本人心知肚明。其玩法如下:

游戏开始了,裁判说:“天黑了”,这是所有其他角色都低头闭上眼睛(不准作弊!)。然后裁判说:“坏人开始活动”,此时坏人抬起头,并相互商议,杀死一个好人。然后裁判说:“天亮了”,此时所有人抬头,被杀死的那个好人宣布出局。剩下的人在村长的主持下,开始判断杀人凶手。每个人可以根据各人的表情反应,判断并提议杀死自己心目中的坏人。不过最终的裁决权属于村长,综合大家的意见杀死一人。此时裁判宣布此人出局。游戏进入下一轮,由天黑到天亮,再有2人出局,如此反复,直到最后好人先被全部杀死,则游戏结束,“邪恶”的一方战胜了“正义”的一方;而另一个结局则是在大家以及村长的英明决断下,坏人被全部杀死,则“正义”的一方战胜了“邪恶”的一方。

现在,我们的问题是,请写出你的思路,并编写一个C/C++语言程序,求出:在坏人有两个(n = 2)的情况下,需要多少个好人(m = ?),才能够使这个游戏比较公平,也就是说,从概率上说,“正义”的一方与“邪恶”的一方胜利的几率最接近于50%。

(此题与下面一题选做一道)

6、在以上的杀人游戏中,还有一个玩法,就是取消村长这个角色,“天亮”后剩余的人每个人投票列出自己心目中最怀疑的2个人,以此决定让谁出局。试问,在此玩法下,上面的问题又何解?

7.C++程序设计

1).写出以下程序的运行结果:

#include

class Base

{

public:

Base()

{

cout
}

Base(const Base &theBase)

{

cout
}

~Base()

{

cout
}

void Open()

{

OnOpen();

}

private:

virtual void OnOpen() = 0;

};

class Derived : public Base

{

public:

Derived()

{

cout
}

Derived(const Derived &theDerived)

{

cout
}

~Derived()

{

cout
}

private:

virtual void OnOpen()

{

//这里可能抛出异常

}

};

Base *CreateInstance()

{

return new Derived();

}

int main()

{

Base *pBase = ::CreateInstance();

if (pBase)

{

pBase->Open();

delete pBase;

}

return 0;

}

2).在1)中,类Base和类Derived的实现有没有问题?如果有,如何修改?

3).说明1)中类Base的Open函数和OnOpen函数的设计目的和意义。

4).使用STL技术修改main()函数中的代码,使之成为异常安全的。

Tags in this post...

面试题 相关文章推荐
宝信软件JAVA工程师面试经历
Aug 19 面试题
说出数据连接池的工作机制是什么?
Apr 19 面试题
请问如下代码执行后a和b的值分别是什么
May 05 面试题
我想声明一个指针并为它分配一些空间, 但却不行。这些代码有什么 问题?char *p; *p = malloc(10);
Oct 06 面试题
创建索引时需要注意的事项
May 13 面试题
叙述DBMS对数据控制功能有哪些
Jun 12 面试题
北京泡泡网网络有限公司.net面试题
Jul 17 面试题
PPP协议组成及简述协议协商的基本过程
May 28 面试题
维德科技C#面试题笔试题
Dec 09 面试题
实体的生命周期
Aug 31 面试题
用Java语言将一个键盘输入的数字转化成中文输出
Jan 25 面试题
Java如何读取CLOB字段
Oct 10 面试题
瀑布模型都有哪些优缺点
Jun 23 #面试题
常见的软件开发流程有哪些
Nov 14 #面试题
MIS软件工程师的面试题
Apr 22 #面试题
软件测试工程师面试问题精选
Oct 28 #面试题
配置管理计划的主要内容有哪些
Jun 20 #面试题
中间件分为哪几类
Sep 18 #面试题
软件测试有哪些?什么是配置项?
Feb 12 #面试题
You might like
Windows下部署Apache+PHP+MySQL运行环境实战
2012/08/31 PHP
PHP把空格、换行符、中文逗号等替换成英文逗号的正则表达式
2014/05/04 PHP
javascript数组与php数组的地址传递及值传递用法实例
2015/01/22 PHP
php命令行(cli)下执行PHP脚本文件的相对路径的问题解决方法
2015/05/25 PHP
PHP结合Ffmpeg快速搭建流媒体服务的实践记录
2018/10/31 PHP
使用composer安装使用thinkphp6.0框架问题【视频教程】
2019/10/01 PHP
JavaScript 脚本将当地时间转换成其它时区
2009/03/19 Javascript
JQuery 构建客户/服务分离的链接模型中Table中的排序分析
2010/01/22 Javascript
document.forms用法示例介绍
2014/06/26 Javascript
js检测判断日期大于多少天的方法
2015/05/04 Javascript
基于JS模仿windows文件按名称排序效果
2016/06/29 Javascript
Javascript中arguments对象的详解与使用方法
2016/10/04 Javascript
Javascript使用SWFUpload进行多文件上传
2016/11/16 Javascript
JavaScript实现鼠标滚轮控制页面图片切换功能示例
2017/10/14 Javascript
nodejs dgram模块广播+组播的实现示例
2019/11/04 NodeJs
Vue2.0 实现页面缓存和不缓存的方式
2019/11/12 Javascript
python3的输入方式及多组输入方法
2018/10/17 Python
如何基于python生成list的所有的子集
2019/11/11 Python
通过代码实例了解Python3编程技巧
2020/10/13 Python
详解python模块pychartdir安装及导入问题
2020/10/22 Python
HTML5 Canvas+JS控制电脑或手机上的摄像头实例
2014/05/03 HTML / CSS
Html5页面二次分享的实现
2018/07/30 HTML / CSS
英国山地公路自行车商店:Tweeks Cycles
2018/03/16 全球购物
法学毕业生自我鉴定
2014/01/31 职场文书
优秀求职信
2014/05/29 职场文书
小学生我的梦想演讲稿
2014/08/21 职场文书
怎样写离婚协议书
2014/09/10 职场文书
2014县政府领导班子三严三实对照检查材料思想汇报
2014/09/26 职场文书
政府班子四风问题整改措施
2014/10/04 职场文书
2015年办公室文秘工作总结
2015/04/30 职场文书
小学六年级毕业感言
2015/07/30 职场文书
导游词之南京莫愁湖公园
2019/11/13 职场文书
Python 语言实现六大查找算法
2021/06/30 Python
浅谈JavaScript浅拷贝和深拷贝
2021/11/07 Javascript
springboot 多数据源配置不生效遇到的坑及解决
2021/11/17 Java/Android
python数据处理之Pandas类型转换
2022/04/28 Python