#include<iostream>
#include<cstring>
char a1[2000], b1[2000];
int a[2000], b[2000], c[2000];
using namespace std;
int main()
{
int i, j, len1, len2, len;
cin >> a1 >> b1;
len1 = strlen(a1);
len2 = strlen(b1);
len = len1 + len2;
if (a1[0] == '0' || b1[0] == '0')
cout << '0';
else
{
for (i = 0; i < len1; i++)
a[i] = a1[len1 - 1 - i] - '0';
for (i = 0; i < len2; i++)
b[i] = b1[len2 - 1 - i] - '0';
for (i = 0; i < len1; i++)
for (j = 0; j < len2; j++)
{
c[i + j] += a[i] * b[j];
c[i + j + 1] += c[i + j] / 10;
c[i + j] %= 10;
}
if (c[len - 1] == 0)
len--;
for (i = len - 1; i >= 0; i--)
cout << c[i];
}
return 0;
}
洛谷P1303 A*B Problem进阶解法
最新推荐文章于 2024-04-23 17:43:50 发布