- 高精度乘法
- 2014-10-17 21:42:05 @
我就是最后一个点过不去,把数组加大十倍过了。
2 条评论
-
denverjin LV 7 @ 2015-08-13 10:24:09
#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;
} -
2014-10-30 19:21:18@
那肯定不是数组的问题,你是不是0没考虑
- 1