1174 through a high-precision multiplication

Description [title]

Product of the sum of two non-negative integers less than 200 bits.

[Enter]

There are two rows of not more than 200 is a non-negative integer, no extra leading zero.

[Output]

Line, i.e., the multiplied result. The results can not have extra leading 0, that is, if the result is 342, you can not output to 0342.

[Sample input]

12345678900
98765432100

[Sample Output]

1219326311126352690000 

Code


#include<iostream>
#include<cstdio>
#include<cmath> #include<cstring> #include<cstdlib> #include<algorithm> using namespace std; int main() { char a1[201],b1[201]; int a[201]={0},b[201]={0},c[10001]={0},lena,lenb,lenc,i,j,x; scanf("%s",a1); scanf("%s",b1); lena=strlen(a1),lenb=strlen(b1); for(i=0;i<lena;i++) a[lena-i]=a1[i]-48; for(i=0;i<lenb;i++) b[lenb-i]=b1[i]-48; for (I = . 1 ; I <= Lena ; I ++) {X = 0 ; for ( int J = . 1 ; J <= LenB ; J ++) {C [I + J -1 ] = C [I + J -1 ] + X + A [I ] * B [J ]; // bit multiplication instead of multiplication, but each one must multiply, so to find what law, is the first bit i + j-1 is i-bits times the j-bit number plus aspirant, this may not necessarily just a 1. But the most important point to note is that to add the original number. 
For example, a two-digit multiplied by two-digit, then when the calculated vertical columns, the result is actually the second plus twice the original can not discard a first number X = C [I + J -1 ] / 10 ; C [IJ + -1 ]% = 10 ; } C [I + LenB ] = X ; } lenc = Lena + LenB ; maximum not more than two digits of the multiplier and, for example, 99 * 99, four such results. why? You see, suppose you have five, then the result must be greater than 10,000, but even 99 * 100 before 9900, and 99 * 99 each are already taking the maximum number, so no more than the while (c [lenc ] = = 0 && lenc > . 1 ) lenc -; for (I = lenc ; I > = . 1 ; I -) COUT << C [I ]; return 0 ; }

Guess you like

Origin www.cnblogs.com/57xmz/p/12370825.html