Question B: "High precision" simple high-precision addition time limit: 1 Sec memory limit: up to MB
Submitted by: 94 resolution: 27
Submitted State [Discussion Version] Topic description Asura King solved the computer's memory limit problem, finally can use the computer for a large magic operation, he handed the Wolf's first task is to calculate two nonnegative integers a, b and, where A and b in the number of digits within 5,000 bits. Input a total of two rows of data, the first behavior of a nonnegative integer A, the second behavior a nonnegative integer b,a, B, the number of bits are within 5000. Output output a non-negative number, that is, the sum of two. Sample input
11111111112222222222
Sample output
3333333333
Tips
#include <iostream> #include <cstring>using namespace Std;int main () { int c,i,j,cnt; int res[1111]; Char a[1111],b[1111]; Gets (a); Gets (b); int Lena=strlen (a); int Lenb=strlen (b); c=0; cnt=0; For (i=lena-1,j=lenb-1;i>=0&&j>=0;i--, j--) { int p= (a[i]-' 0 ') + (b[j]-' 0 ') +c; res[cnt++]=p%10; C=P/10; } while (i>=0) { int p= (a[i]-' 0 ') +c; res[cnt++]=p%10; C=P/10; i--; } while (j>=0) { int p= (b[j]-' 0 ') +c; res[cnt++]=p%10; C=P/10; j--; } if (c) { res[cnt++]=c; } for (i=cnt-1;i>=0;i--) { cout<<res[i]; } Puts (""); return 0;}
Question B: "High precision" simple high-precision addition