2134 - [数值问题]高精度乘以高精度

通过次数

0

提交次数

0

时间限制 : 1 秒 内存限制 : 128 MB
高精度乘以高精度(highmul/c/cpp) 

【问题描述】 

输入两个高精度正整数a和b(a,b位数<=200),求两数的乘积。

【输入格式】highmul.in

<span>输入共两行,分别为a和b。</span> 

<span>【输出格式】highmul.out</span> 

<span>输出共一行,表示两个数的积。</span> 

<span>【输入样例1】&nbsp;</span><span><br />

1234567890
1234567890

<br />

<br />

<span style="line-height:21px;"></span> 

<span>【输出样例1】</span> 

1524157875019052100

<br />

<br />

题目输入

题目输出

输入/输出样例

输入格式


                        

输出格式


                        

C++解答

#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int a1[202],b1[202],c[408];
char a[202],b[202];
int main()
{
	gets(a);
	gets(b);
	a1[0]=strlen(a);
	b1[0]=strlen(b);
	for(int i=1;i<=a1[0];++i)
	  a1[i]=a[a1[0]-i]-48;
	for(int i=1;i<=b1[0];++i)
	  b1[i]=b[b1[0]-i]-48;
	for(int i=1;i<=a1[0];++i)
     {
	   int x=0;
	   for(int j=1;j<=b1[0];++j)
	   {
			c[i+j-1]=a1[i]*b1[j]+x+c[i+j-1];
			x=c[i+j-1]/10;
			c[i+j-1]=c[i+j-1]%10;
	   }
	   c[i+b1[0]]=x;
     }
   int lenc=a1[0]+b1[0];
   while(c[lenc]==0&&lenc>1)--lenc;
   for(int i=lenc;i>=1;--i)
	 printf("%d",c[i]);
   system("pause");
   return 0;
}