1234xq @ 2024-01-27 20:39:10
#include<bits/stdc++.h>
using namespace std;
char a1[10001], a2[10001];
int s1[10001], s2[10001];
long long c[10001];
int main()
{
scanf("%s%s", a1, a2);
int la1 = strlen(a1);
int la2 = strlen(a2);
for (int i = 0; i < la1; i++)
s1[la1 - i] = a1[i] - '0';
for (int i = 0; i < la2; i++)
s2[la2 - i] = a2[i] - '0';
int lc = la1 + la2;
for (int i = 1; i <= la1; i++)
for (int j = 1; j <= la2; j++)
{
c[i + j-1] += (long long)s1[i] * s2[j];
c[i + j ] += c[i + j-1] / 10;
c[i + j-1] %= 10;
}
if (c[lc] == 0 && lc > 0)lc--;
for (int i = lc; i > 0; i--)
cout << c[i];
return 0;
}
by han_zheng @ 2024-01-27 21:12:00
对个毛线,问题出在最后
if (c[lc] == 0 && lc > 0)lc--;
这一行。因为可能不只有一个前导零,所以if要改成while
by 1234xq @ 2024-01-29 19:46:17
@han_zheng 过了,谢谢大佬。