Product
Product |
The Problem
The problem is to multiply two integers X, Y. (0<=X,Y<10250)
The Input
The input will consist of a set of pairs of lines. Each line in pair contains one multiplyer.
The Output
For each input pair of lines the output line should consist one integer the product.
Sample Input
12 12 2 222222222222222222222222
Sample Output
144 444444444444444444444444
注意:当乘数有0时,也要有输出的...
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 250+10
using namespace std;
int main()
{
char s1[N],s2[N];
int num[2*N];
while(scanf("%s%s",s1,s2)!=EOF)
{
// cout<<s1<<" "<<s2<<endl;
int n,m;
memset(num,0,sizeof(num));
n=strlen(s1);m=strlen(s2);
// cout<<n<<" "<<m<<endl;
for(int i=m-1;i>=0;i--)
for(int j=n-1,k=m-1-i;j>=0;j--,k++)
{
num[k]+=(s2[i]-'0')*(s1[j]-'0');
// cout<<num[k]<<endl;
if(num[k]>9)
{
num[k+1]+=num[k]/10;
num[k]%=10;
}
}
int f=0;
for(int i=2*N-1;i>=1;i--)
{
if(!f&&!num[i])
continue;
f=1;
printf("%d",num[i]);
}
printf("%d\n",num[0]);
}
return 0;
}