程序员面试经典试题



《程序员面试经典试题》由会员分享,可在线阅读,更多相关《程序员面试经典试题(10页珍藏版)》请在文档大全上搜索。
1、1、现有 1000 个苹果,10 个盒子,问各个盒子内应该分别放入多少个苹果,才能使得用户要买任意 1 至 1000 之间的一个苹果数,都可以给他(卖的时候是整个盒子卖,不能拆盒子的包装)。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 null.int 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