ACM部分练习题目答案

ACM部分练习题目答案

ID:40529818

大小:49.00 KB

页数:8页

时间:2019-08-04

上传者:U-2441
ACM部分练习题目答案_第1页
ACM部分练习题目答案_第2页
ACM部分练习题目答案_第3页
ACM部分练习题目答案_第4页
ACM部分练习题目答案_第5页
资源描述:

《ACM部分练习题目答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

ACM部分习题答案:A+BProblemTimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):100972AcceptedSubmission(s):33404ProblemDescriptionCalculateA+B.InputEachlinewillcontaintwointegersAandB.Processtoendoffile.OutputForeachcase,outputA+Binoneline.SampleInput11SampleOutput2#includeIntmain(){intx,y,s;while(scanf("%d%d",&x,&y)!=EOF){s=x+y;printf("%d ",s);}return0;}SumProblemTimeLimit:1000/500MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):85964AcceptedSubmission(s):19422ProblemDescriptionHey,welcometoHDOJ(HangzhouDianziUniversityOnlineJudge).Inthisproblem,yourtaskistocalculateSUM(n)=1+2+3+...+n.InputTheinputwillconsistofaseriesofintegersn,oneintegerperline.OutputForeachcase,outputSUM(n)inoneline,followedbyablankline.Youmayassumetheresultwillbeintherangeof32-bitsignedinteger.SampleInput1100SampleOutput15050#includeintmain(){intn;longints; while(scanf("%d",&n)!=EOF){s=0;while(n>0){s=s+n;n--;}printf("%ld ",s);}return0;}A+BProblemIITimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):58216AcceptedSubmission(s):10500ProblemDescriptionIhaveaverysimpleproblemforyou.GiventwointegersAandB,yourjobistocalculatetheSumofA+B.InputThefirstlineoftheinputcontainsanintegerT(1<=T<=20)whichmeansthenumberoftestcases.ThenTlinesfollow,eachlineconsistsoftwopositiveintegers,AandB.Noticethattheintegersareverylarge,thatmeansyoushouldnotprocessthembyusing32-bitinteger.Youmayassumethelengthofeachintegerwillnotexceed1000.OutputForeachtestcase,youshouldoutputtwolines.Thefirstlineis"Case#:",#meansthenumberofthetestcase.Thesecondlineistheanequation"A+B=Sum",SummeanstheresultofA+B.Notetherearesomespacesinttheequation.Outputablanklinebetweentwotestcases.SampleInput212112233445566778899998877665544332211SampleOutputCase1:1+2=3Case2:112233445566778899+998877665544332211=1111111111111111110#include#includeintmain(){charx[1001],y[1001],z[1001];intn,i,j,k,m,o;scanf("%d",&n);o=n;while(n--){scanf("%s%s",x,y);i=strlen(x);j=strlen(y); for(k=0,m=0;i>0&&j>0;i--,j--){m+=x[i-1]-'0'+y[j-1]-'0';z[k++]=m%10+'0';m/=10;}for(;i>0;i--){m+=x[i-1]-'0';z[k++]=m%10+'0';m/=10;}for(;j>0;j--){m+=y[j-1]-'0';z[k++]=m%10+'0';m/=10;}if(m>0)z[k++]=m%10+'0';printf("Case%d: %s+%s=",o-n,x,y);for(;k>0;k--)printf("%c",z[k-1]);printf(" ");if(n)printf(" ");}return0;}LettheBalloonRiseTimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):24082AcceptedSubmission(s):7343ProblemDescriptionContesttimeagain!Howexciteditistoseeballoonsfloatingaround.Buttotellyouasecret,thejudges'favoritetimeisguessingthemostpopularproblem.Whenthecontestisover,theywillcounttheballoonsofeachcolorandfindtheresult.Thisyear,theydecidetoleavethislovelyjobtoyou.InputInputcontainsmultipletestcases.EachtestcasestartswithanumberN(0#includevoidmain(){intn,i,j,k,t,a[1001];charh[1001][16];while(scanf("%d",&n)!=EOF){if(n==0)break;for(i=0;i<=n;++i)a[i]=0;t=i=k=0;while(ik){k=a[i];t=i;}}printf("%s ",h[t]);}}ElevatorTimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):12849AcceptedSubmission(s):6646ProblemDescriptionThehighestbuildinginourcityhasonlyoneelevator.ArequestlistismadeupwithNpositivenumbers.Thenumbersdenoteatwhichfloorstheelevatorwillstop,inspecifiedorder.Itcosts6secondstomovetheelevatoruponefloor,and4secondstomovedownonefloor.Theelevatorwillstayfor5secondsateachstop.Foragivenrequestlist,youaretocomputethetotaltimespenttofulfilltherequestsonthelist.Theelevatorisonthe0thflooratthebeginninganddoesnothavetoreturntothegroundfloor whentherequestsarefulfilled.InputTherearemultipletestcases.EachcasecontainsapositiveintegerN,followedbyNpositivenumbers.Allthenumbersintheinputarelessthan100.AtestcasewithN=0denotestheendofinput.Thistestcaseisnottobeprocessed.OutputPrintthetotaltimeonasinglelineforeachtestcase.SampleInput1232310SampleOutput1741#includeintmain(){inta,b,n,t;while(scanf("%d",&n)!=EOF&&n){t=0;b=0;t+=n*5;//停的总时间累加起来while(n--){scanf("%d",&a);if(a>b)t+=6*(a-b);//与前次比若上升elseif(a#includeintmain(){intl,s,i;chara[1000];while(scanf("%s",a)){l=strlen(a);s=0;if(l==1&&(strcmp(a,"0")==0))break;else{for(i=0;i9){l=0;while(s){l+=s%10;s/=10;}s=l;}s=(s%10+s/10);printf("%d ",s);}}return0;}AsEasyAsA+BTimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others) TotalSubmission(s):12198AcceptedSubmission(s):4870ProblemDescriptionThesedays,Iamthinkingaboutaquestion,howcanIgetaproblemaseasyasA+B?Itisfairlydifficultytodosuchathing.Ofcourse,Igotitaftermanywakingnights.Giveyousomeintegers,yourtaskistosortthesenumberascending(升序).Youshouldknowhoweasytheproblemisnow!Goodluck!inputInputcontainsmultipletestcases.ThefirstlineoftheinputisasingleintegerTwhichisthenumberoftestcases.Ttestcasesfollow.EachtestcasecontainsanintegerN(1<=N<=1000thenumberofintegerstobesorted)andthenNintegersfollowinthesameline.Itisguarantiedthatallintegersareintherangeof32-int.OutputForeachcase,printthesortingresult,andonelineonecase.SampleInput232139147258369SampleOutput123123456789#includeintmain(){intn,i;scanf("%d",&n);for(i=0;ia[k+1]){t=a[k];a[k]=a[k+1];a[k+1]=t;}printf("%d",a[0]);for(j=1;j

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。
大家都在看
近期热门
关闭