杭电oj的1002(大数加法),哪错了?该怎么解决
杭电oj的1002(大数加法),哪错了?
题目:
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
我的程序:
题目:
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 <string.h>
#include <stdio.h>
#define N 1000
int main(void)
{
char a[N], b[N];
int c[N+1]={0};
int t;
scanf("%d", &t);
int loops;
for(loops = 1; loops<=t; loops++) {
scanf("%s %s", a, b);
int la = strlen(a);
int lb = strlen(b);
int length = (la > lb ? la : lb)+1;
int i, j, k=0;
for(i=la-1, j=lb-1; i>=0&&j>=0; i--, j--) {
c[k++] = a[i]-'0'+b[j]-'0';
}
while(i>=0)
c[k++] = a[i--]-'0';
while(j>=0)
c[k++] = b[j--]-'0';
int carrier = 0;
for(i=0; i<k; i++) {
c[i] += carrier;
if(c[i] > 9) {
c[i] %= 10;
carrier = 1;