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");
}
} 展开
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");
}
} 展开
展开全部
#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;
}
应该是正确的。。。
#include<stdlib.h>
int main()
{ int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
printf("%d\n",a+b);
system("pause");
return 0;
}
应该是正确的。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个题是hdu的。。。目的是用大数解决,平时用的int之类的是无法解决的。。。你自己用数组写一个大数加法吧。。。很简单的。。。加法是最简单的。。。其他的就稍微难一点
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询