class CArray : " />
2024年3月29日發(fā)(作者:我愛吃番茄)

程序員面試經(jīng)典試題
1、現(xiàn)有1000個蘋果,10個盒子,問各個盒子內(nèi)應(yīng)該分別放入多
少個蘋果,才能使得用戶要買任意1至1000之間的一個蘋果數(shù),都可
以給他(賣的時候是整個盒子賣,不能拆盒子的包裝)。
2、請仔細(xì)閱讀下面的資料:
1)材料一:CArray
template< class TYPE, class ARG_TYPE > 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 ud to
access objects stored in the array.
Often a reference to TYPE. ARG_TYPE is a parameter that is
pasd 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 accesd.
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 ud to reference objects stored in the list. Can be a
reference. Remarks:
The CList class supports ordered lists of nonunique objects
accessible quentially 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, u 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. Becau the new block can be in a new memory location,
the pointer returned by realloc is not guaranteed to be the
pointer pasd through the memblock argument.
4)請指出下面這段代碼可能會出現(xiàn)的問題
CList g_ValueList;
CArray g_ValuePool;
void AddNewValue (const V ARIANT& newValue)
{
g_l(&g_ValuePool[g_(newVal
ue)]);
}
3、有一無符號整型數(shù)組,大小為10, 初始的數(shù)值隨機,但在[0,
99]之間。請用C語言寫一個過濾程序,令數(shù)組內(nèi)的數(shù)據(jù)互不相等。
說明:
1.若數(shù)組內(nèi)有相等的數(shù)據(jù),可令某一數(shù)值加1或減1作出偏移,直
至不等為止。
2.數(shù)組內(nèi)的數(shù)據(jù)只能在[0, 99]之間。
3.保持?jǐn)?shù)組內(nèi)的數(shù)據(jù)位置不變,即對應(yīng)下標(biāo)不變。
4、按要求編寫以下函數(shù)。
功能:將給定緩沖區(qū)中的#字符移到字符串尾部
函數(shù)名稱:ChangeToTail
入口參數(shù):pSZ指向緩沖區(qū)的指針, nSize緩沖區(qū)長度
出口:pSZ所指緩沖區(qū)中的#字符被移到緩沖區(qū)尾部
返回值:在出口緩沖區(qū)中第一個#的位置,若緩沖區(qū)中無#字符則返
回-1 說明:如傳入#W#W#W#WW#,10 則傳出時應(yīng)轉(zhuǎn)換為
WWWWW#####并且返回值為5
int ChangeToTail(BYTE* pSZ, UINT nSize)
{
// Todo:請在此加入您的代碼
}
5、在金山,有一個非常經(jīng)典有趣的游戲,稱為殺人游戲。此游戲
角色有:好人(m人)、壞人(n人)、村長(1人)、裁判(1人)。
角色采用一定方式(如:抓鬮)分配。村長、裁判兩個角色是公開的,
而好人、壞人兩個角色則只要裁判和本人心知肚明。其玩法如下:
游戲開始了,裁判說:“天黑了”,這是所有其他角色都低頭閉
上眼睛(不準(zhǔn)作弊!)。然后裁判說:“壞人開始活動”,此時壞人
抬起頭,并相互商議,殺死一個好人。然后裁判說:“天亮了”,此
時所有人抬頭,被殺死的那個好人宣布出局。剩下的人在村長的主持
下,開始判斷殺人兇手。每個人可以根據(jù)各人的表情反應(yīng),判斷并提
議殺死自己心目中的壞人。不過最終的裁決權(quán)屬于村長,綜合大家的
意見殺死一人。此時裁判宣布此人出局。游戲進(jìn)入下一輪,由天黑到
天亮,再有2人出局,如此反復(fù),直到最后好人先被全部殺死,則游
戲結(jié)束,“邪惡”的一方戰(zhàn)勝了“正義”的一方;而另一個結(jié)局則是
本文發(fā)布于:2024-03-29 06:16:05,感謝您對本站的認(rèn)可!
本文鏈接:http://m.newhan.cn/zhishi/a/1711664166301197.html
版權(quán)聲明:本站內(nèi)容均來自互聯(lián)網(wǎng),僅供演示用,請勿用于商業(yè)和其他非法用途。如果侵犯了您的權(quán)益請與我們聯(lián)系,我們將在24小時內(nèi)刪除。
本文word下載地址:程序員面試經(jīng)典試題.doc
本文 PDF 下載地址:程序員面試經(jīng)典試題.pdf
| 留言與評論(共有 0 條評論) |