漠怀 @ 2019-12-15 12:56:43
#include<bits/stdc++.h>
using namespace std;
int a[2100];
int b[2100];
int c[4100000] = {0};
void read(int *p)
{
char ch = getchar();
while (ch < '0'||ch > '9') ch = getchar();
p[1] = ch - '0';
p[0] = 1;
ch = getchar();
while (ch >= '0'&&ch <= '9')
{
p[++p[0]] = ch - '0';
ch = getchar();
}
for (int i = 1;i <= p[0] / 2;i++)
{
int t = p[i];
p[i] = p[p[0] - i + 1];
p[p[0] - i + 1] = t;
}
}
void ab_mult(int const *a,int const *b,int *c)
{
c[0] = a[0] + b[0] - 1;
for (int i = 1;i <= a[0];i++)
for (int j = 1;j <= b[0];j++)
c[i+j-1] += a[i] * b[j];
for (int i = 1;i <= c[0];i++)
{
c[i+1] += c[i]/10;
c[i] %= 10;
}
while (c[c[0]+1])
{
c[0]++;
c[c[0]+1] += c[c[0]]/10;
c[c[0]] %= 10;
}
}
int main()
{
read(a);
read(b);
ab_mult(a,b,c);
for (int i = c[0];i >= 1;i--) cout<<c[i];
return 0;
}
by 金苹果gold @ 2019-12-15 22:47:03
答案是零,就输不出来
by Monkey_Hunter @ 2020-01-22 18:42:25
#include<bits/stdc++.h>
using namespace std;
int a[2100];
int b[2100];
int c[4100000] = {0};
void read(int *p)
{
char ch = getchar();
while (ch < '0'||ch > '9') ch = getchar();
p[1] = ch - '0';
p[0] = 1;
ch = getchar();
while (ch >= '0'&&ch <= '9')
{
p[++p[0]] = ch - '0';
ch = getchar();
}
for (int i = 1;i <= p[0] / 2;i++)
{
int t = p[i];
p[i] = p[p[0] - i + 1];
p[p[0] - i + 1] = t;
}
}
void ab_mult(int const *a,int const *b,int *c)
{
c[0] = a[0] + b[0] - 1;
for (int i = 1;i <= a[0];i++)
for (int j = 1;j <= b[0];j++)
c[i+j-1] += a[i] * b[j];
for (int i = 1;i <= c[0];i++)
{
c[i+1] += c[i]/10;
c[i] %= 10;
}
while (c[c[0]+1])
{
c[0]++;
c[c[0]+1] += c[c[0]]/10;
c[c[0]] %= 10;
}
}
int main()
{
read(a);
read(b);
ab_mult(a,b,c);
for (int i = c[0];i >= 1/*这里改成i>1*/;i--) cout<<c[i];
return 0;
}