资源描述:
《杭电ACM部分题答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1000A+BProblemTimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/32768K(Java/Others)TotalSubmission(s):158161 AcceptedSubmission(s):50186ProblemDescriptionCalculateA+B. InputEachlinewillcontaintwointegersAandB.Processtoendoffile. OutputForeachca
2、se,outputA+Binoneline. SampleInput11 SampleOutput2 AuthorHDOJ Statistic
3、 Submit
4、 Discuss
5、Note#includeintmain(){inta,b;while(scanf("%d%d",&a,&b)!=EOF)printf("%d",a+b);}1002A+BProblemIITimeLimit:2000/1000MS(Java/Others) MemoryLimit:65536/3
6、2768K(Java/Others)TotalSubmission(s):84367 AcceptedSubmission(s):15966ProblemDescriptionIhaveaverysimpleproblemforyou.GiventwointegersAandB,yourjobistocalculatetheSumofA+B. InputThefirstlineoftheinputcontainsanintegerT(1<=T<=20)whichmeansthenumberoft
7、estcases.ThenTlinesfollow,eachlineconsistsoftwopositiveintegers,AandB.Noticethattheintegersareverylarge,thatmeansyoushouldnotprocessthembyusing32-bitinteger.Youmayassumethelengthofeachintegerwillnotexceed1000. OutputForeachtestcase,youshouldoutputtwolin
8、es.Thefirstlineis"Case#:",#meansthenumberofthetestcase.Thesecondlineistheanequation"A+B=Sum",SummeanstheresultofA+B.Notetherearesomespacesinttheequation.Outputablanklinebetweentwotestcases. SampleInput212112233445566778899998877665544332211 SampleOutput
9、Case1:1+2=3Case2:112233445566778899+998877665544332211=1111111111111111110 AuthorIgnatius.L Statistic
10、 Submit
11、 Discuss
12、Note#include#includeintmain(){charstr1[1001],str2[1001];intt,i,len_str1,len_str2,len_max,num=1,k;scanf("%d",&t);g
13、etchar();while(t--){inta[1001]={0},b[1001]={0},c[1001]={0};scanf("%s",str1);len_str1=strlen(str1);for(i=0;i<=len_str1-1;++i)a[i]=str1[len_str1-1-i]-'0';scanf("%s",str2);len_str2=strlen(str2);for(i=0;i<=len_str2-1;++i)b[i]=str2[len_str2-1-i]-'0';if(len_s
14、tr1>len_str2)len_max=len_str1;elselen_max=len_str2;k=0;for(i=0;i<=len_max-1;++i){c[i]=(a[i]+b[i]+k)%10;k=(a[i]+b[i]+k)/10;}if(k!=0)c[len_max]=1;printf("Case%d:",num);num++;printf("%s+%s=",str1,str2);if(c[len_max]==1)printf("1")