期末考试补充测验.ppt

上传人:wuy****n92 文档编号:64733165 上传时间:2022-12-01 格式:PPT 页数:16 大小:218.50KB
返回 下载 相关 举报
期末考试补充测验.ppt_第1页
第1页 / 共16页
期末考试补充测验.ppt_第2页
第2页 / 共16页
点击查看更多>>
资源描述

《期末考试补充测验.ppt》由会员分享,可在线阅读,更多相关《期末考试补充测验.ppt(16页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、期末考试补充测验1.Sumofevennumbers2DescriptionGivenanumberN(evenorodd),calculate2+4+.+n(nisthelargestevennumbersmallerthanN).Printoutthesum.InputThefirstlineisanintegerm,indicatingthenumberoftestcases.Thenfollowmlines.TheilinecontainsapositivenumberN_i.OutputForeachnumberN_i,printthesumof2+4+.+n_i(n_iisthel

2、argestevennumbersmallerthanN_i)inasingleline.SampleInput258SampleOutput6201.Sumofevennumbers3#includeusingnamespacestd;intmain()intcount,num,sum;cincount;for(inti=0;inum;sum=0;for(intj=2;j=num;j+=2)sum+=j;coutsumendl;2.GradeRecordManagement4DescriptionTherearesomestudentsgraderecords,informatof“name

3、grade”.Inordertoeasetheviewandmanagementoftherecordseasily,youareaskedtodevelopaprogramtoprintouttherecordsaccordingtothegrades.Thatis,thenamesareprintedintheorderofgrades.InputTotally,thereare8recordsandeachrecordoccupiesaline.Onlylettersanddigitsappearinthenameofastudent(i.e.therewillbenospaceinan

4、ame).Eachnamecontainsatmost20lettersor(and)digits.Allgradesareintegersintherangeof0100.OutputEachgradeperline,followedbythestudentshavingthisgrade.Forstudentshavingthesamegrade,theyarelistedinthesameline,withthesameorderasintheinput.Hints:Youcanusetwoarraystostorethenamesandgrades.SampleInputWangYi9

5、0LiMing90HuRui50ZhangLi65LiLei80ZhangFei65ZhaoSan70ChenZi100SampleOutput100ChenZi90WangYiLiMing80LiLei70ZhaoSan65ZhangLiZhangFei50HuRui2.GradeRecordManagement5#defineSIZE8#defineLEN25intmain()charnameSIZELEN;intgradeSIZE;for(inti=0;inamei;cingradei;/rankfor(inti=SIZE-1;i0;-i)for(intj=0;ji;+j)if(grad

6、ejgradej+1)chartmpLEN;strcpy(tmp,namej);strcpy(namej,namej+1);strcpy(namej+1,tmp);inttmp2=gradej;gradej=gradej+1;gradej+1=tmp2;/printfor(inti=0;iSIZE;+i)if(i=0|gradeigradei-1)coutgradei;coutgradei+1)coutsalpcnttarget;while(sal0)yr=1;sum=12*sal;while(sumtarget)sal+=(sal*pcnt)/100;sum+=12*sal;yr+;cout

7、yrsalpcnttarget;2.StringReversion9DescriptionGivenavalididentifierinCprograms,pleasewriteaprogramtoreverseitbyrespectivelyreversingtwopartsseparatedby_.InputThefirstlineisanintegerm,indicatingthenumberoftestcases.Thentherearemlinesandeachlinecontainsastring.Astringwillcontainnomorethan100charactersa

8、ndthereisoneorless_.OutputForeachtestcase,printoutthestringreversed.SampleInput2John_Smithint_45_meSampleOutputnhoJ_htimStni_54_emStringReversion10voidreversePart(char,int,int);/reversepartofthestringintmain()intcount;cincount;for(intx=0;xstr;for(inti=0;istrlen(str);i+)if(stri=_)mark=i;break;reverse

9、Part(str,0,mark-1);reversePart(str,mark+1,strlen(str)-1);coutstrhigh)return;for(inti=low;ich;while(ch!=#)/Initialzevairalbeforeachlineofinputfor(inti=0;i-1&countlast0ch;if(countdigit0countdigit1)countdigit0=countdigit1;/Sortthenumbersintmax,tmp1,tmp2;/Setthesecondcolumntobedigits0.9;for(inti=0;i=9;i

10、+)counti1=i;for(inti=0;i=9;i+)max=findMax(count,i);tmp1=counti0;tmp2=counti1;counti0=countmax0;counti1=countmax1;countmax0=tmp1;countmax1=tmp2;/Printouttheresultsfor(inti=0;i0)coutcounti1(counti0);if(i0)cout,;elsecoutch;intfindMax(intcount2,intlow)intmax=low;for(inti=low+1;icountmax0)max=i;elseif(co

11、unti0=countmax0&counti1countmax1)max=i;returnmax;4.Changetouppercase13DescriptionGivenalinecontainsmultiplewords,changethefirstcharacterineachwordtouppercase.InputAlinecontainingmultiplewords.Thelinecontainslessthan100characters.OutputThesamelinewiththefirstcharacterofeachwordbeinguppercase.SampleIn

12、putPleasechangemetoupper-case.SampleOutputPleaseChangeMeToUpper-case.Changetouppercase14intlength(char*string1)for(inti=0;+i)if(string1i=0)returnI;chartoUpperCase(charc)if(c=a&c=z)return(char)(c-(a-A);returnc;voidtoUpperCase(char*string1,char*string2)intlength1=length(string1);inttimes=0;intstatus=1

13、;for(inti=0;ilength1;+i)if(string1i=)string2i=string1i;status=1;elseif(status=1)string2i=toUpperCase(string1i);elsestring2i=string1i;status=0;intmain()charstring1100;charstring2100;cin.getline(string1,100);toUpperCase(string1,string2);coutstring2;5.Cyclingthewords15DescriptionGivenalinecontainsNword

14、s,printtheNlines.Thefirstlineisthesameastheinput.Afterprintingeachline,thefirstwordofthislineinputtotheendofthenextline.InputAlinecontainsNwords.Nisnotgivenintheproblem:youneedtocountthenumberofwordsintheinputlinetofinditout.Thelinecontainslessthan100characters.OutputNlines.Thefirstlineequalstheinpu

15、t.FortherestN-1lines,thefirstwordinalineinputtotheendinthenextline.SampleInputPleasethinkaboutitcarefullySampleOutputPleasethinkaboutitcarefullythinkaboutitcarefullyPleaseaboutitcarefullyPleasethinkitcarefullyPleasethinkaboutcarefullyPleasethinkaboutitCyclingthewords16intlength(char*string1)for(inti

16、=0;+i)if(string1i=0)returni;intsplit(char*string1,char*string2)intlength1=length(string1);intcount=1;for(inti=0;ilength1;+i)string2i=string1i;if(string1i=)+count;string2i=0;returncount;voidprint(char*string1)intlength1=length(string1);intwords=split(string1,string1);intstart=0;for(inti=0;iwords;+i)intstart2=start;for(intj=i;jwords;+j)cout(string1+start2);start2+=length(string1+start2)+1;start2=0;for(intj=0;ji;+j)cout(string1+start2);start2+=length(string1+start2)+1;coutendl;start+=length(string1+start)+1;intmain()charstring1100;cin.getline(string1,100);print(string1);

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 大学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁