A + B Problem II C语言

A+BProblemIITimeLimit:2000/1000MS(Java/Others)MemoryLimit:65536/32768K(Java/Others)To... A + B Problem II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 70801 Accepted Submission(s): 12909

Problem Description
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.

Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.

Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.

Sample Input
2
1 2
112233445566778899 998877665544332211

Sample Output
Case 1:
1 + 2 = 3

Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110

我是新手,研究两天没能整出来,还望哪位高人能指指我程序的错误或者贡献一下您的程序,十分感谢
#include<stdio.h>
void main()
{
int T,m,n,h=1,i,j,k,q,w,e;
char A[1000],B[1000],Sum[1000];
scanf("%d",&T);
for(h=1;h<=T;h++)
{
i=0;
j=0;
k=0;
gets(A);
gets(B);
m=strlen(A);
n=strlen(B);
if(m<=n)
{
i=0;
j=0;
k=0;
while(k<=n-1)
{
Sum[k]=A[i]+B[j];
if(Sum[k]>=10)
{
Sum[k]=Sum[k]%10;
Sum[k+1]=1;
}
i++;
j++;
k++;
}
}
else
{
i=0;
j=0;
k=0;
while(k<=m-1)
{
Sum[k]=A[i]+B[j];
if(Sum[k]>=10)
{
Sum[k]=Sum[k]%10;
Sum[k+1]=1;
}
i++;
j++;
k++;
}
}
printf("Case %d:\n",h);
puts(A);
printf(" + ");
puts(B);
printf(" = ");
puts(Sum);
printf("\n\n");
}
}
展开
 我来答
顺畅又灵秀丶君子兰1175
2011-01-26 · TA获得超过1247个赞
知道小有建树答主
回答量:889
采纳率:100%
帮助的人:628万
展开全部
#include<stdio.h>
#include<stdlib.h>
int main()
{ int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
printf("%d\n",a+b);
system("pause");
return 0;
}

应该是正确的。。。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
sichuanliuyong
2011-02-01
知道答主
回答量:40
采纳率:0%
帮助的人:16.9万
展开全部
这个题是hdu的。。。目的是用大数解决,平时用的int之类的是无法解决的。。。你自己用数组写一个大数加法吧。。。很简单的。。。加法是最简单的。。。其他的就稍微难一点
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式