ACM长数加法
前几天,在这个论坛上发的一个帖子,给我提的意见,可以说毫无用处。我听说,CSDN上高手不少,我也相信,比我强的人很多,可是他们太让我失望了,我今天在检查这个程序又发现一个问题,我才明白,回答我上个帖子的人根本就没认真看,我希望,各位高手,给我点帮助,谢谢了,小弟我真的需要你们的帮助。
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>
#include<string.h>
#include<memory.h>
#define LEN 1001
main()
{
char arr1[LEN],arr2[LEN],arr3[LEN];
int i,j,n,l,l1,l2,s;
scanf("%d",&n);
for(j=0;j<n;j++)
{
scanf("%s%s",arr1,arr2);
printf("Case %d\n",j+1);
printf("%s + %s =",arr1,arr2);
l1=strlen(arr1);
l2=strlen(arr2);
memset(arr3,'0',LEN);
l=l1>l2?l1:l2;
s=l1<l2?l1:l2;
for(i=0;i<s;i++)
{
arr3[l-i]+=arr1[l1-i-1]+arr2[l2-i-1]-96;
if(arr3[l-i]>'9')
{
arr3[l-i]-=10;
arr3[l-i-1]+=1;
}
}
if(l1-i>0||l2-i>0)
{
if(l2>l1)
strcpy(arr1,arr2);
for(;i<l;i++)
{
arr3[l-i]+=arr1[l-i-1]-48;
if(arr3[l-i]>'9')
{
arr3[l-i]-=10;
arr3[l-i-1]+=1;
}
}
}
arr3[l+1]='\0';
if(arr3[0]=='0')
printf("%s\n",arr3+1);
else
printf("%s\n",arr3);
printf("\n\n");
}
}
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>
#include<string.h>
#include<memory.h>
#define LEN 1001
main()
{
char arr1[LEN],arr2[LEN],arr3[LEN];
int i,j,n,l,l1,l2,s;
scanf("%d",&n);
for(j=0;j<n;j++)
{
scanf("%s%s",arr1,arr2);
printf("Case %d\n",j+1);
printf("%s + %s =",arr1,arr2);
l1=strlen(arr1);
l2=strlen(arr2);
memset(arr3,'0',LEN);
l=l1>l2?l1:l2;
s=l1<l2?l1:l2;
for(i=0;i<s;i++)
{
arr3[l-i]+=arr1[l1-i-1]+arr2[l2-i-1]-96;
if(arr3[l-i]>'9')
{
arr3[l-i]-=10;
arr3[l-i-1]+=1;
}
}
if(l1-i>0||l2-i>0)
{
if(l2>l1)
strcpy(arr1,arr2);
for(;i<l;i++)
{
arr3[l-i]+=arr1[l-i-1]-48;
if(arr3[l-i]>'9')
{
arr3[l-i]-=10;
arr3[l-i-1]+=1;
}
}
}
arr3[l+1]='\0';
if(arr3[0]=='0')
printf("%s\n",arr3+1);
else
printf("%s\n",arr3);
printf("\n\n");
}
}
...全文



