Otion @ 2022-12-28 14:14:46
因为这里面的字符倒序我直接用的reverse函数 下标从0开始,所以和大家的公式可能就不太一样了
#include <bits/stdc++.h>
using namespace std;
const int N = 4020;
char A[2005], B[2005];
int a[2005], b[2005];
int c[N];
int main()
{
scanf("%s", A);
scanf("%s", B);
int len_a = strlen(A);
int len_b = strlen(B);
reverse(A, A + len_a);
reverse(B, B + len_b);
for (int i = 0; i < len_a; i++)
{
a[i] = A[i] - '0';
}
for (int i = 0; i < len_b; i++)
{
b[i] = B[i] - '0';
}
for (int j = 0; j < len_a; j++)
{
for (int k = 0; k < len_b; k++)
{
c[j + k] += a[j] * b[k];
if (c[j + k] > 9)
{
c[j + k + 1] = c[j + k] / 10;
c[j + k] %= 10;
}
}
}
int flag = 4019;
while (c[flag] == 0)
{
if (flag == 0)
{
cout << 0;
return 0;
}
flag--;
}
for (int i = flag; i >= 0; i--)
{
cout << c[i];
}
return 0;
}
by _maojun__ @ 2022-12-28 14:21:31
@Tapper
c[j + k + 1] = c[j + k] / 10;
改成
c[j + k + 1] += c[j + k] / 10;
by Otion @ 2022-12-28 14:27:49
@_maojun__
谢谢大佬谢谢大佬
关注了