杭电hdu上的链接http://acm.hdu.edu.cn/showproblem.php?pid=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
解题思路:刚开始做这道题的时候,以为是A+B的题也难不到哪去,谁知道改了好几个小时。开始试了int,不行,又改long,不行,然后改long long,还是不行。只能另外想一种方法了:用大位数加法,用数组装数字,然后从个位开始逐位相加,过十进一。开始的时候想肯定是用数组了,肯定不会是字符数组。但是做着做着发现不行,数组的长度无法确定,想起来字符数组有个strlen的用法,就改用字符数组了。
以下是具体代码:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #define N 1005 5 using namespace std; 6 7 int count = 0; 8 int a[N]; 9 int b[N]; 10 int he[N]; 11 char sza[N]; 12 char szb[N]; 13 14 void calcuation() { 15 int flag = 1; 16 int len1,len2; 17 len1 = strlen(sza); 18 len2 = strlen(szb); 19 int i,j,k,l; 20 i = 0; 21 while(sza[i] != '