原题链接 来自洛谷https://www.luogu.com.cn/problem/P1303
图片来自题解 P1303 【A*B Problem】 - AFO - 洛谷博客 (luogu.com.cn)
#include <bits/stdc++.h>
using namespace std;
int num0[20100];
int num1[20100];
int num[20100];
int n0 = 0, n1 = 0, n = 0;
int main()
{
int i, j, t;
char c;
while(~scanf("%c", &c))
{
if (c == '\r') continue;
if (c == '\n') break;
num0[n0++] = c-'0';
}
for (i = 0; i < n0/2; i++)
swap(num0[i], num0[n0-i-1]);
while(~scanf("%c", &c))
{
if (c == '\r') continue;
if (c == '\n') break;
num1[n1++] = c-'0';
}
for (i = 0; i < n1/2; i++)
swap(num1[i], num1[n1-i-1]);
for (i = 0; i < n0; i++)
{
for (j = 0; j < n1; j++)
{
num[i+j] += num0[i] * num1[j];
num[i+j+1] += num[i+j] / 10;
num[i+j] %= 10;
}
}
for (i = n0+n1; !num[i] && i > 0; i--);
for (; i >= 0; i--)
printf ("%d", num[i]);
return 0;
}