- 高精度乘法
- 2013-08-26 19:08:53 @
无语怎么回事啊,第三个和第四个点过不了啊,求神牛帮助!
1 条评论
-
denverjin LV 7 @ 2015-08-13 10:23:41
#include <cstdio>
#include <cstring>
using namespace std;
struct Bigint
{
int n,a[20005];
Bigint()
{
n = 0;
memset(a,0,sizeof(a));
}
void operator = (const char string[10005])
{
n = strlen(string);
for (int i = 0;i < n;i++)
a[i] = string[n-1-i]-'0';
}
Bigint operator * (const Bigint &x)
{
Bigint t;t.n = n+x.n-1;
for (int i = 0;i < n;i++)
for (int j = 0;j < x.n;j++)
t.a[i+j] += a[i]*x.a[j];
for (int i = 0;i < t.n;i++)
{
t.a[i+1] += t.a[i] / 10;
t.a[i] %= 10;
}
if (t.a[t.n]) t.n++;
return t;
}
};
int main()
{
char x[10005],y[10005];
scanf("%s%s",x,y);
Bigint a,b;
a = x;
b = y;
Bigint ans;
ans = a*b;
for (int i = ans.n-1;i >= 0;i--)
printf("%d",ans.a[i]);
printf("\n");
return 0;
}
- 1