
Accept: 399 Submit: 1028
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
In this problem, you will be concerned with integers with very large numbers of digits. You must write code which will repeatedly accept (until end of file) two lines each containing an unsigned integer, and output the product of the two input unsigned integers. The output must not contain any leading zeros.
You can assume that each integer will contain at most 80 digits. The input ends with an end of file.
Sample Input
03421298123
Sample Output
44391636
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
int a[100];
int b[100];
char s1[100];
char s2[100];
int c[200];
int lena, lenb, i, j, len;
void multi(){
memset(c, 0, sizeof(c));
len = lena+lenb;
for(i=0;i<lena;++i)
for(j=0;j<lenb;++j){
c[i+j] += a[i]*b[j];
}
for(i=0;i<len;++i){
c[i+1] += c[i]/10;
c[i] %= 10;
}
len++;
while(len>0 && !c[len-1])
len--;
}
int main(){
//freopen("in.txt", "r", stdin);
while(cin>>s1>>s2){
lena = strlen(s1);
lenb = strlen(s2);
for(i=lena-1;i>=0;--i)
a[lena-1-i] = s1[i] - '0';
for(i=lenb-1;i>=0;--i)
b[lenb-1-i] = s2[i] - '0';
multi();
if(len==0)
printf("0");
else
for(i=len-1;i>=0;i--)
cout<<c[i];
printf("\n");
}
//fclose(stdin);
return 0;
}