33. }
34.
35. return 0;
36.}
Whatisthecorrectresult?
A.11111111
B.12121212
C.11112222
D.21212121
【此题答案貌似应该是22221111】
注:
答案确实是22221111。
我就不吐槽什么了。
因为没有虚函数,所以没有4字节的虚函数表,这样一个B类对象就是8字节,A类对象是4字节。
在seta函数中,取A[1]对象时,程序会跳过4字节(而不是一个正常B对象应该跳过的8字节),所以取A[1]的a实际上得到的是B[0]的a,取A[0]的a实际上得到的是B[0]的b。
9.1of1000bottlesofwaterispoisonedwhichwillkillaratin1weekiftheratdrunkanyamoutofthewater.Giventhebottlesofwaterhavenovisualdifference,howmanyratsareneededatleasttofindthepoisonedonein1week?
(5Points)
A.9
B.10
C.32
D.Noneoftheabove
注:
给1~1000的瓶子二进制编号,10个老鼠按位站好,哪个瓶子在这一位上是1就给这只老鼠喝一点。
最后看那些老鼠死了,该位置1,得出的数就是毒瓶。
10.Whichofthefollowingstatement(s)equal(s)value1inCprogramminglanguage?
(5Points)
A.thereturnvalueofmainfunctionifprogramendsnormally
B.return(7&1)
C.char*str="microsoft";returnstr=="microsoft"
D.return"microsoft"=="microsoft"
E.Noneoftheabove
注:
显然这份答案的作者不知道有个优化叫做“启用字符串池”(VS里的/GF)。
如果不启用此优化,那么任意两个即使相等的字符串常量也会被存为两个副本,这样C和D的指针比较就会失败。
11.Ifyoucomputed32bitsignedintegersFandGfrom32bitsignedXusingF=X/2andG=(X>>1),andyoufoundF!
=G,thisimpliesthat(5Points)
A.Thereisacompilererror
B.Xisodd
C.Xisnegative
D.F-G=1
E.G-F=1
12.Howmanyrectanglesyoucanfindfrom3*4grid?
(5Points)
A.18
B.20
C.40
D.60
E.Noneofaboveiscorrect
13.Onelinecansplitasurfaceto2part,2linecansplitasurfaceto4part.Given100lines,notwoparallellines,notreelinesjoinatsamepoint,howmanypartscan100linesplit?
(5Points)
A.5051
B.5053
C.5510
D.5511
注:
高二找规律题。
n(n+1)/2+1
14.Whichofthefollowingsortingalgorithm(s)is(are)stablesorting?
(5Points)
A.bubblesort
B.quicksort
C.heapsort
D.mergesort
E.Selectionsort
注:
稳定是指(任意)两个相等的元素,排序前后其相对前后位置不变。
选择排序、快速排序、希尔排序、堆排序不是稳定的排序算法,而冒泡排序、插入排序、归并排序和基数排序是稳定的排序算法。
15.Model-View-Controller(MVC)isanarchitecturalpatternthatfrequentlyusedinwebapplications.Whichofthefollowingstatement(s)is(are)correct:
(5Points)
A.Modelsoftenrepresentdataandthebusinesslogicsneededtomanipulatethedataintheapplication
B.Aviewisa(visual)representationofitsmodel.Itrendersthemodelintoaformsuitableforinteraction,typicallyauserinterfaceelement
C.Acontrolleristhelinkbetweenauserandthesystem.Itacceptsinputfromtheuserandinstructsthemodelandaviewtoperformactionsbasedonthatinput
D.ThecommonpracticeofMVCinwebapplicationsis,themodelreceivesGETorPOSTinputfromuseranddecideswhattodowithit,handingovertocontrollerandwhichhandcontroltoviews(HTML-generatingcomponents)
E.Noneoftheabove
16.wecanrecoverthebinarytreeifgiventheoutputof(5Points)
A.Preordertraversalandinordertraversal
B.Preordertraversalandpostordertraversal
C.Inordertraversalandpostordertraversal
D.Postordertraversal
17.Givenastringwithncharacters,supposeallthecharactersaredifferentfromeachother,howmanydifferentsubstringsdowehave?
(5Points)
A.n+1
B.n^2
C.n(n+1)/2
D.2^n-1
E.n!
18.Giventhefollowingdatabasetable,howmanyrowswillthefollowingSQLstatementupdate?
(5Points)
A.1
B.2
C.3
D.4
E.5
19.WhatistheshortestpathbetweennodeSandnodeT,giventhegraphbelow?
Note:
thenumbersrepresentthelengthsoftheconnectednodes.(13Points)
A.17
B.18
C.19
D.20
E.21
注:
从T开始往前倒退,非常简单
20.GivenasetofNballsandoneofwhichisdefective(weighslessthanothers),youareallowedtoweighwithabalance3timestofindthedefective.WhichofthefollowingarepossibleN?
(13Points)
A.12
B.16
C.20
D.24
E.28
注:
27以下都可以。
实际上,如果允许m次比较,那么N<=3^m都可以。
关键是要想到比如3个球,我们可以比较其中两个,不平衡当然知道哪个轻,平衡就是第三个轻。