高精度乘法
高精度乘法
include
include
include
include
include
include
include
include
include
define MAXN 0x3f3f3f3f
using namespace std;
int main()
{
string a;
string b;
int x[10000];
int y[10000];
int c[10000];
cin >> a >> b;
for (int i = 0; i < a.size();i++)//反向储存
x[i] = a[a.size() - i - 1]-'0';
for (int i = 0; i < b.size();i++)
y[i] = b[b.size() - i - 1]-'0';
for (int i = 0; i < a.size();i++)//
{
for (int j = 0; j < b.size();j++)
{
c[i + j]+= x[i] * y[j];//错位相加
if(c[i+j]>9)//进位
{
c[i + j + 1]+= c[i + j] / 10;
c[i + j] = c[i + j] % 10;
}
}
}
int total = a.size() + b.size();//两个数相乘不会超过两个数的位数和
while (c[total] == 0 && total> 0)//去除前导0
{
total--;
}
for (int i = total; i >= 0;i--)
return 0;
}