華為c語(yǔ)言筆試題-(HUAWEIClanguagetestquestions-)_第1頁(yè)
華為c語(yǔ)言筆試題-(HUAWEIClanguagetestquestions-)_第2頁(yè)
華為c語(yǔ)言筆試題-(HUAWEIClanguagetestquestions-)_第3頁(yè)
華為c語(yǔ)言筆試題-(HUAWEIClanguagetestquestions-)_第4頁(yè)
華為c語(yǔ)言筆試題-(HUAWEIClanguagetestquestions-)_第5頁(yè)
已閱讀5頁(yè),還剩33頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

華為c語(yǔ)言筆試題'-(HUAWEIClanguagetestquestions-)HUAWEIexamcollectionWhat'stheuseof1.static?(pleasespecifyatleasttwo.)inafunctionbody,avariablethatisdeclaredasstatickeepsitsvalueconstantduringthecallofthisfunction.withinamodule(butoutsidethefunction),avariabledeclaredstaticcanbeaccessedbythefunctionusedwithinthemodule,butnotaccessiblebyotherfunctionsoutsidethemodule.Itisalocalglobalvariable.withinamodule,astaticallydeclaredfunctioncanonlybecalledbyotherfunctionswithinthismodule.Thatis,thisfunctionis1imitedtousewithinthelocalscopeofthemodulethatdeclaresitwhatisthedifferencebetweenreferenceandpointer?referencesmustbeinitialized,pointersdonothaveto.afterreferenceinitializationcannotbechanged,thepointercanchangetheobjectthatitrefersto.thereisnoreferencetonullvalues,buttherearepointerstonullvalues.describethebasiccharacteristicsofreal-timesystemsPerformspecifictasksatagiventime,withreal-timeandreliability.arethereanydifferencesbetweenglobalandlocalvariablesinmemory?Ifso,whatisthedifference?Globalvariablesarestoredinstaticglobaldatasegments,whilelocalvariablesareonthestack.whatisabalancedtwoforktree?Theleftandrightsubtreesarebalancedtwoforkstrees,andtheabsolutevalueofthedifferencebetweentheleftandrightsubtreesisnotgreaterthan1.whatcausesthestackoverflowgenerally?Thereisnorecyclingofwasteresources.whatfunctionscannotbedeclaredasvirtualfunctions?Theconstructorfunctioncannotbedeclaredavirtualfunction.whatisthetimecomplexityofthebubblesortalgorithm?Thetimecomplexityis0(n2).writetheifstatementthatcomparesthefloatxwiththezerovalue.Whatkindofnetworkprotocoldoes10.Internetadopt?Whatistheprimaryhierarchyoftheprotocol?Tcp/ipprotocolThemainstructureisasfollows:applicationlayer/transportlayer/networklayer/datalinklayer/physicallayer.Whatprotocolsareusedfor11.InternetphysicaladdressandIPaddresstranslation?ARP(Address,Resolution,Protocol)(addressresolutionprotocol)Whatarethetwopartsoftheencodingofthe12.IPaddress?TheIPaddressconsistsoftwoparts,thenetworknumberandthehostnumber.However,youhavetousethesubnetmasktopressandthentodistinguishbetweennetworkbitsandwhichhostsarebits.13.,theuserinputM,Nvalue,from1toNstartcyclecount,counttoM,outputthevalueuntilalltheoutput.WritetheCprogram.Circularlinkedlist,withtheremainingoperationsdone14.cannotdoswitch().Theargumenttypeis:Theparametersofswitchcannotbereal.ShanghaiHUAWEIapointerontheproblemofprogrammingIntALnSize],whichhidesanumberof0,andtherestofthe0noninteger,writeafunctionintFunc(int*,A,int,nSize),sothatAmove0totheback,not0integersmovedtoThearrayisorderedinfrontandreturnsthesubscriptofthefirstelementintheoriginaldataof0.(asfaraspossiblewithoutusingtheauxiliaryspaceandconsideringtheefficiencyandtheexception),theannotationspecificationandthedesignideaaregivenHUAWEIwrittenquestionscontaininganswers[softwareengineeringquestions]Writeaprogramthatrequiresfunctions:findthecombinationof1,2,5,threenumbers,differentnumbers,andacombinationof100.Suchas:100,lisacombination,51plus19,5isacombination....PleasewriteinC++language.Answer:theeasiestwaytothinkaboutitis..:LetXbethenumberof1,yisthenumberof2,Zisthenumberof5,andnumberisthecombinationnumberNotethat0<=x<=100,0<=y<=50,0<=z=20,andsocanbeprogrammedas:Number=0;For(x=0;x<=100;x++)For(y=0;y<=50;y++)For(z=0;z<=20;z++)If((x+2*y+5*z)==100)Number++;Cout<<number<<endl;Theprogramabovecycles100*50*20times,TheefficiencyisreallytoolowInfact,thesubjectisaclearmathematicalproblem,notapurelyprogrammingone.Mysolutionisasfollows:Becausex+2y+5z=100Sox+2y=100-5z,andz<=20,x<=100,y<=50So(x+2y)<=100,and(x+5z)isevenForZcycles,thepossiblevaluesforXareasfollows:Z=0,x=100,98,96,...0Z=l,x=95,93,,1Z=2,x=90,88,…,0Z=3,x=85,83,,1Z=4,x=80,78,,0Z=19,x=5,3,1Z=20,x=0Therefore,anoddnumberoflessthan100oftheodd+90withinanevennumberof+1withinatotalnumberof+95oroddnumberswithin+5,Namely:(46+43)+(41+38)+(36+33)+(31+28)+(26+23)+(21+18)+(51+48)+(16+13)+(11+8)+(+1)+(6+3)?Evennumbers(including0)withinanevennumberofMcanberepresentedasm/2+l=(m+2)/2TheoddnumberwithinanoddnumberofMcanalsobeexpressedas(m+2)/2Therefore,thetotalnumberofcombinationscanbeprogrammedNumber=O;For(intm=0;m<=100;m+=5)Number+=(m+2)/2;Cout<<number<<endl;Thisprogramonlyneeds21cyclesandtwovariablestogettheanswer,muchmoreefficientthantheoneaboveTimessimplybecauseofsomesimplemathematicalanalysisThisprovesagain:computerprograms=datastructures+algorithms,andalgorithmsarethesouloftheprogram,askanyprojectWhensoftwareisimplemented,wemustselectsuchresourcesascurrentresourceconstraints,userrequirementsconstraints,anddevelopmenttimeconstraintsOptimalalgorithmunderfourkindsofconstraints.Andnevergetahand,andimmediatelyputtogetheraprogramwiththeeasiesttothinkofIt,snotthebehaviorofaprofessionalR&Dstaff.So,isthatoneoftheeasiestalgorithmsoutofthequestion?No,thisalgorithmcanbeusedtovalidatethenewalgorithmThecorrectnessofthedebuggingphase,whichisveryuseful.Inmanylargecompanies,suchasMicrosoft,thisapproachhasbeenadoptedInthetestingphase,someimportantprogramswhichneedgoodalgorithmareimplemented,andthegoodalgorithmisusedatthesametimeEasytothinkalgorithmstoverifythisprocedure,iftheresultsofthetwoalgorithmsareinconsistent(andmosteasilythoughtofbythealgorithm)Theproofiscorrect,thentheoptimizationalgorithmisoutoforderandneedstobemodified.Examplescanbeexpressedas:#ifdefDEBUGInt,simple();#endifInt,optimize();Inafunction:Result=optimize();ASSERT(result-simple());Thus,inthedebuggingphase,iftheresultsofthesimplealgorithmandtheoptimizationalgorithmareinconsistent,theassertionisasserted.Atthesametime,intheprocessThereleaseversionoftheorderdoesnotcontainthebulkysimple()function.AnylargeengineeringsoftwareneedstobedesignedinadvanceGooddebuggingmeans,andtheonementionedhereisausefulmethod.Astudent'sinformationis:name,studentnumber,gender,ageandotherinformation,usingalinkedlist,puttogethertheinformationofthesestudents,givenaage,inthelistisequaltotheagestudentinformationdeletestudentage.ttinclude"stdio.h"”ffincludeconio.hStructstu{Charname[20];Charsex;Intno;Intage;Structstu*next;}*linklist;Structstu*creatlist(intn)IInti;//histheheadnode,Pisthepreviousnode,andSisthecurrentnodeStruct,Stu,*h,*p,*s;H=(struct,Stu*)malloc(sizeof(struct,Stu));H->next=NULL;P=h;For(i=0;i<n;i++)S=(struct,Stu*)malloc(sizeof(struct,Stu));P->next=s;printf(“請(qǐng)輸入信息的學(xué)生:姓名性別年齡不\n");scanf(“%s%c%d%d",S->名稱->,和性別,和S-〉沒(méi)有,&S->年齡);s=下一個(gè)null;P=s;)printf("創(chuàng)造成功!”);返回(h);)無(wú)效deletelist(structstu的int)!結(jié)構(gòu)體;而(年齡)!=一個(gè))P=s;下一個(gè);)如果(=NULL)printf("記錄是不存在的?!保黄渌腎下一個(gè);printf("刪除成功!”);))空顯示(結(jié)構(gòu)){下一個(gè);當(dāng)(S!=null)printf("%s%c%d%d\n",S-〉名稱->性別的,S->不,S年齡);下一個(gè);}}國(guó)際main(){結(jié)構(gòu)體;年齡、年齡;printf(“請(qǐng)輸入詳細(xì)說(shuō)明:長(zhǎng)度:\n");scanf(“強(qiáng)d”,和N);S=creatlist(N);顯示器(s);printf(“請(qǐng)輸入年齡:\n");scanf(“斷1”,年齡);deletelist(的時(shí)代);顯示器(s);返回0;)2、實(shí)現(xiàn)一個(gè)函數(shù),把一個(gè)字符串中的字符從小寫轉(zhuǎn)為大寫。包括“stdio.h”包括“是的?!碧擁敚ㄗ址址?)I因?yàn)椋ǎ?“0”;“++”,“++”){如果(*>=""&*<=Z)我們*S-32;其他的*美國(guó)二;*我們="0";國(guó)際main()(char*,*我們;char[20];printf(“請(qǐng)輸入一個(gè)字符串:\n");scanf(“%s”,SS);S=SS;鞋面(S,我們);printf(“結(jié)果:\n%s\n”,美國(guó));getchO;}隨機(jī)輸入一個(gè)數(shù),判斷它是不是對(duì)稱數(shù)(回文數(shù))(如不能用字符串庫(kù)函數(shù)31211232145254)。****函數(shù)名稱:對(duì)稱性功能:判斷一個(gè)數(shù)時(shí)候?yàn)榛匚臄?shù)(12135653)輸入:長(zhǎng)整型的數(shù)輸出:若為回文數(shù)返回值為1其他0xix xL?*1**1**L?xt?xL?xt??lxxtz*1*xL??Jxxl??J>*£*xL?*1**1**1??lx*1**1*?X*xlx?lxxlxxl*xL?*4x?lxxlx?lx ?lx?lx ?Jz?Jxxl*?lx*p?ZJ*ZJ*>p?*JX*p?ZJ*ZJ*>p? zjx *p? ZJ* zjx zjs ?JSZJ**p? zj*>p?zjs*******/無(wú)符號(hào)char對(duì)稱(長(zhǎng)n)(長(zhǎng)我,臨時(shí)工;i=n;臨時(shí)值=0;而(我)/不用出現(xiàn)長(zhǎng)度問(wèn)題,將數(shù)按高低位掉換溫度=溫度10+i%10;i=10;返回(溫度=n);)方法一/*功能:判斷字符串是否為回文數(shù)字實(shí)現(xiàn):先將字符串轉(zhuǎn)換為正整數(shù),再將正整數(shù)逆序組合為新的正整數(shù),兩數(shù)相同則為回文數(shù)字輸入:char*:待判斷的字符串輸出:返回:0:正確;1:待判斷的字符串為空;2:待判斷的字符串不為數(shù)字;3:4:待判斷的字符串溢出字符串不為回文數(shù)字;無(wú)符號(hào)issymmetry(char*)(char*s;長(zhǎng)的N=0;長(zhǎng)n=0;長(zhǎng)ntemp=0;判斷輸入是否為空/**/如果(0)返回1;將字符串轉(zhuǎn)換為正整數(shù)/**/同時(shí)(*!“0”判斷字符是否為數(shù)字/**/如果(p<0\"\I|*P'年\")返回2;Judgingwhetherapositiveintegeroverflow/**/If((*p-\'0\')>(4294967295-(nNumber*10))Return4;NNumber=(*p-\'0\')+(nNumber*10);P++;)/*digitalreversecombination,directlycopytheupstairsmastercode,nowonder,oh.N=nNumber;While(n)Judgingwhetherapositiveintegeroverflow/**/If((n%10)>(4294967295-(nTemp*10))Return3;NTemp=nTemp*10+n%10;N/=10;)Comparedwiththeoriginalnumber/reverseisequal.If(nNumber==nTemp)Return3;Return0;)Methodtwo/*Function:DetermineswhetherastringisapalindromenumberRealization:Firstwegetthelengthofthestring,andthencomparethecorrespondingbitcharactersofthestringinturnInput:Char*s:thestringtobejudgedOutput:nothingReturn:0:correct:1:thestringtobejudgednull;2:thestringtobejudgedisnotnumeric;3:stringisnotpalindromenumbersWasn*UnsignedIsSymmetry_2(char*s)Char*p=s;IntnLen=0;Inti=0;Shoulddeterminewhethertheinputisempty.If(*s=\'\\0\')Return1;Getthelengthofthestring/**/While(*p==\'\\0\'){Todeterminewhetheracharacterisdigital/**/If(*p<\'0\'*p>\'9\'||)Return2;NLen++;P++;)*lengthisodd,notforpalindromenumbers.If(nLen%2=0)Return4;/*lengthlisapalindromicnumber.If(nLen=1)Return0;Inordertocomparethesamecharacterscorresponding/**/P=s;I=nLen/2-1;While(I)(If(*(p+i)=*(p+nLen-i-1))Return3;I~~;)Return0;}Seekallprimenumbersof2?2000.Haveenoughmemory,askforassoonaspossibleAnswer:Intfindvalue[2000]={2};Staticintfind=l;Booladjust(intvalue)Assert(value>=2);If(value==2)returntrue;For(inti=0;i<=find;i++)If(value%findvalue[i]==0)Returnfalse;Findvalue[find++];Returntrue;HUAWErslastthreebigquestionsA,B,C,Dfourprocesses,Awritedatatothebuf,B,C,D,readdatatothebuf,WhenAfinisheswriting,andB,C,andDarereadonce,Acanwriteagain.ImplementedwithP,Voperations.willone-waylistreverse,suchasABCDintoDCBA,canonlysearchlistonce.,twoforktreetwochiIdrenchangepositions,thatis,leftturnright,leftturnright.YoucantuseapassHUAWEItestquestions:2007.03.31HUAWEIwrittenexaminationquestionsoneortwoTosayafew:(feelHUAWEI,butso,althoughmypointsarenothigh,becausealotofquestionsIdotohimisreallyinsultingmyIQ)38outof3cowsrunfastest,usingasitethatprovidesonly6racesatatime,requiringthefastestmethod.Igaveoneofthemoststupidanswers,becauseIfoundtherewere38peopleinawrittentest,andIdidn'tknowwhatitmeantTheeffectisasfollows:thestaffknowtheboss'sage,don'tknowhisdaughter,sage,thebossof3daughtersagesumis13,multipliedbythebossage,andonlyadaughterolderthan5,andthe4age?(therearelotsofanswersontheInternet!)Theoriginaltitleisacontestofmathematicalmodelingcontestforcollegestudentsbefore2002,Thatis,astudentintherainfromthedormitorytothecafeteriatoeat,200metersdistance,askiswalkinglessrainorrunningless?Thisquestionsimplifiesmostoftheassumptions.ThereareonlyafewquestionsleftforyoutosolveHUAWErslatesttestquestionsandtheiranalysisTheoutputproblemof1.printfPrintf total);//this,is,rightPrintf(total);//this,is,wrongPrintf("hello");//but,this,is,rightthelengthofanintegertypeChar1subsections,8bitsUnsignedshort[int][signed]shortintShort2bytes,16bits[signed]intUnsignedintTypeintinVCis4subsections,32bits,or16bits,2bytesLong[int]Unsignedlong[int]Typelongis32bits,4bytesFloat32,4Double64,8Longdouble128,16Char8,abytethatholdstheactualcharacteroftheASCIIcodeFindoutthemistakesandcorrectthemChar*my_cpy(char*,SRC,int,len){Chardest[1024];Memcpy(DeST,SRC,len);Returndest;Isthereaproblemwiththefunctionabove?Ifitindicateswhereitis,ifnot,afunctionfunctiondescriptionisgiven.Answer:ArraysshouldbeinitializedMemcpydoesnotdeterminewhethertocrossthebounds,sobeforecalling,youshoulddeterminewhetherornottheboundsarecrossedRestshouldnotbereturnedbecausethearrayisappliedinsidethefunction,sothefunctiondisappearsaftertheendofthefunction,andthepointerbecomesawildpointer,pointingtoanillegaladdressThelastoneishiddenChar*memcpy(char,*dest,const,char,*src,int,len)Char*pDest=(char*)dest;Char*pSrc=(char*)src;Intpos;For(pos=0;pos<len;pos++)PDest[pos]=pSrc[pos];Return(char*)pDest;Thereisnoproblemtojudgewhethertheillegalpointerassert(dest=NULLSRC||!!=NULL);conditionsforFLASEdisplayDonotcallotherfunctions,writeamemcpyfunction,functionprototypeforVoid*memcpy(void,*dest,void,*src,sizet,length);-gooduseofassertions一/*memcpy-copydoesnotoverlapthememoryblock.Voidmemcpy(void*,pvTo,void*,pvFrom,sizet,size)IVoid*pbTo=(byte*)pvTo;Void*pbFrom=(byte*)pvFrom;ASSERT(pvTo!=NULL&&pvFrom!=NULL);/*memoryblockoverlap?Iftheoverlap,theuseofmemmove*/ASSERT(pbTo>=pbFrom+sizepbFrom>=pbTo+size||);While(size->0)*pbTo++==*pbFrom++;Return(pvTo);)AndCommonfunctionprogramming:Char*strcpy(char,*strDest,const,char,*strSrc)iASSERT(strDest!=NULL&&strSrc!=NULL);Char*addr=strDest;While(*strDest++=*strSrc++)NULL;//NULLcanbeomitted,butitismoreconducivetocompilerdiscoveryerrorsReturnaddr;Void*memcpy(void,*dest,const,void,*src,int,count)ASSERT(dest!=NULL&&SRC!=NULL);For(inti=0;i<

溫馨提示

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

最新文檔

評(píng)論

0/150

提交評(píng)論