您好,欢迎访问三七文档
【杭电ACM1000】A+BProblemProblemDescriptionCalculateA+B.InputEachlinewillcontaintwointegersAandB.Processtoendoffile.OutputForeachcase,outputA+Binoneline.SampleInput11SampleOutput2#includestdio.hintmain(){inta,b;while(scanf(%d%d,&a,&b)!=EOF)printf(%d\n,a+b);return0;}【杭电ACM1001】SumProblemProblemDescriptionHey,welcometoHDOJ(HangzhouDianziUniversityOnlineJudge).Inthisproblem,yourtaskistocalculateSUM(n)=1+2+3+...+n.InputTheinputwillconsistofaseriesofintegersn,oneintegerperline.OutputForeachcase,outputSUM(n)inoneline,followedbyablankline.Youmayassumetheresultwillbeintherangeof32-bitsignedinteger.SampleInput1100SampleOutput15050#includestdio.hintmain(){intn,i,sum=0;while(scanf(%d,&n)!=EOF){for(i=1;i=n;++i)sum=sum+i;printf(%d\n\n,sum);sum=0;}return0;}【杭电ACM1002】A+BProblemIIProblemDescriptionIhaveaverysimpleproblemforyou.GiventwointegersAandB,yourjobistocalculatetheSumofA+B.InputThefirstlineoftheinputcontainsanintegerT(1=T=20)whichmeansthenumberoftestcases.ThenTlinesfollow,eachlineconsistsoftwopositiveintegers,AandB.Noticethattheintegersareverylarge,thatmeansyoushouldnotprocessthembyusing32-bitinteger.Youmayassumethelengthofeachintegerwillnotexceed1000.OutputForeachtestcase,youshouldoutputtwolines.ThefirstlineisCase#:,#meansthenumberofthetestcase.ThesecondlineistheanequationA+B=Sum,SummeanstheresultofA+B.Notetherearesomespacesinttheequation.Outputablanklinebetweentwotestcases.SampleInput212112233445566778899998877665544332211SampleOutputCase1:1+2=3Case2:112233445566778899+998877665544332211=1111111111111111110#includestdio.h#includestring.hintshu(chara){return(a-'0');}intmain(){chara[1000],b[1000];intnum[1001];intn,i,j=1,al,bl,k,t;scanf(%d,&n);while(n--){getchar();if(j!=1)printf(\n);scanf(%s,a);al=strlen(a);scanf(%s,b);bl=strlen(b);k=(albl)?al:bl;for(i=0;i=k;i++)num[i]=0;t=k;for(k;al0&&bl0;k--){num[k]+=shu(a[--al])+shu(b[--bl]);if(num[k]/10){num[k-1]++;num[k]%=10;}}while(al0){num[k--]+=shu(a[--al]);if(num[k+1]/10){num[k]++;num[k+1]%=10;}}while(bl0){num[k--]+=shu(b[--bl]);if(num[k+1]/10){num[k]++;num[k+1]%=10;}}printf(Case%d:\n,j++);printf(%s+%s=,a,b);for(i=0;i=t;i++){if(i==0&&num[i]==0)i++;printf(%d,num[i]);}printf(\n);}return0;}
本文标题:杭电ACM试题答案
链接地址:https://www.777doc.com/doc-3445893 .html