程序員面試經(jīng)典試題_第1頁
程序員面試經(jīng)典試題_第2頁
程序員面試經(jīng)典試題_第3頁
程序員面試經(jīng)典試題_第4頁
程序員面試經(jīng)典試題_第5頁
已閱讀5頁,還剩5頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、1、現(xiàn)有 1000 個蘋果,10 個盒子,問各個盒子內(nèi)應該分別放入多少個蘋果,才能使得用戶要買任意 1 至 1000 之間的一個蘋果數(shù),都可以給他(賣的時候是整個盒子賣,不能拆盒子的包裝)。2、請仔細閱讀下面的資料:1)材料一:CArraytemplate class CArray : publicCObjectParameters:TYPETemplate parameter specifying the type of objects stored in the array.TYPE is a parameter that is returned by CArray.ARG_TYPETem

2、plate parameter specifying the argument type used to access objectsstored in the array.Often a reference to TYPE. ARG_TYPE is a parameter that is passed toCArray.Remarks:The CArray class supports arrays that are are similar to C arrays, but candynamically shrink and grow as necessary.Array indexes a

3、lways start at position 0. You can decide whether to fixthe upper bound or allow the array to expand when you add elements pastthe current bound. Memory is allocated contiguously to the upper bound,even if some elements are CArray:Add (ARG_TYPE newElement);Return Value:The index of the adde

4、d element.Parameters:ARG_TYPETemplate parameter specifying the type of arguments referencingelements in this array.newElementThe element to be added to this array.TYPE& CArray:operator (int nIndex);Parameters:TYPETemplate parameter specifying the type of elements in this array.nIndexIndex of the ele

5、ment to be accessed.Remarks:Returns the array reference of element at the specified index.2)材料二:CListtemplateclass CList : public CObjectParameters:TYPEType of object stored in the list.ARG_TYPEType used to reference objects stored in the list. Can be a reference.Remarks:The CList class supports ord

6、ered lists of nonunique objects accessiblesequentially or by value.CList lists behave like doubly-linked lists.void CList:AddTail(ARG_TYPE newElement);Parameters:ARG_TYPETemplate parameter specifying the type of the list element (can be areference).newElementThe element to be added to this list.Rema

7、rks:Adds a new element or list of elements to the tail of this list. The list canbe empty before the operation.3)材料三: reallocreallocReallocate memory blocks.void *realloc(void *memblock, size_t size);Return Value:The return value points to a storage space that is guaranteed to be suitablyaligned for

8、 storage of any type of object. To get a pointer to a type otherthan void, use a type cast on the return value.Remarks:The size argument gives the new size of the block, in bytes. The contentsof the block are unchanged up to the shorter of the new and old sizes,although the new block can be in a dif

9、ferent location. Because the newblock can be in a new memory location, the pointer returned by realloc isnot guaranteed to be the pointer passed through the memblock argument.4)請指出下面這段代碼可能會出現(xiàn)的問題CList g_ValueList;CArray g_ValuePool;void AddNewValue (const VARIANT& newValue)g_ValueList.AddTail(&g_Valu

10、ePoolg_ValuePool.Add(newValue);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.保持數(shù)組內(nèi)的數(shù)據(jù)位置不變,即對應下標不變。4、 按要求編寫以下函數(shù)。功能:將給定緩沖區(qū)中的#字符移到字符串尾部函數(shù)名稱:ChangeToTail入口參數(shù):pSZ 指向緩沖區(qū)的指針, nSize 緩沖區(qū)長度出口:pSZ 所指緩沖區(qū)中的#字符被移到緩沖區(qū)尾部返回值:在出口緩沖區(qū)中第一

11、個#的位置,若緩沖區(qū)中無#字符則返回-1說 明 : 如 傳 入 #W#W#W#WW# , 10 則 傳 出 時 應 轉(zhuǎn) 換 為WWWWW#并且返回值為 5int ChangeToTail(BYTE* pSZ, UINT nSize)/ Todo:請在此加入您的代碼5、在金山,有一個非常經(jīng)典有趣的游戲,稱為殺人游戲。此游戲角色有:好人(m 人)、壞人(n 人)、村長(1 人)、裁判(1 人)。角色采用一定方式(如:抓鬮)分配。村長、裁判兩個角色是公開的,而好人、壞人兩個角色則只要裁判和本人心知肚明。其玩法如下:游戲開始了,裁判說:“天黑了”,這是所有其他角色都低頭閉上眼睛(不準作弊?。H缓蟛门?/p>

12、說:“壞人開始活動”,此時壞人抬起頭,并相互商議,殺死一個好人。然后裁判說:“天亮了”,此時所有人抬頭,被殺死的那個好人宣布出局。剩下的人在村長的主持下,開始判斷殺人兇手。每個人可以根據(jù)各人的表情反應,判斷并提議殺死自己心目中的壞人。不過最終的裁決權(quán)屬于村長,綜合大家的意見殺死一人。此時裁判宣布此人出局。游戲進入下一輪,由天黑到天亮,再有2 人出局,如此反復,直到最后好人先被全部殺死,則游戲結(jié)束,“邪惡”的一方戰(zhàn)勝了“正義”的一方;而另一個結(jié)局則是在大家以及村長的英明決斷下,壞人被全部殺死,則“正義”的一方戰(zhàn)勝了“邪惡”的一方?,F(xiàn)在,我們的問題是,請寫出你的思路,并編寫一個 C/C+語言程序,

13、求出:在壞人有兩個(n = 2)的情況下,需要多少個好人(m = ?),才能夠使這個游戲比較公平,也就是說,從概率上說,“正義”的一方與“邪惡”的一方勝利的幾率最接近于 50%。(此題與下面一題選做一道)6、在以上的殺人游戲中,還有一個玩法,就是取消村長這個角色,“天亮”后剩余的人每個人投票列出自己心目中最懷疑的 2 個人,以此決定讓誰出局。試問,在此玩法下,上面的問題又何解?7.C+程序設計1).寫出以下程序的運行結(jié)果:#include class Basepublic:Base()cout Base() endl;Base(const Base &theBase)cout Base(const Base &theBase) endl;Base()cout Base() endl;void Open()OnOpen();private:virtual void OnOpen() = 0;class Derived : public Basepublic:Derived()cout Derived() endl;Derived(const Derived &theDerived)cout Deriv

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論