tijie<AC>
2025-05-31 14:07:25
发布于:四川
16阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int a[110], b[110], c[210];
string func(string sa, string sb) {
int la = sa.size(), lb = sb.size(), lc = la + lb;
for (int i = 0; i < la; i++) a[i] = sa[la-i-1] - '0';
for (int i = 0; i < lb; i++) b[i] = sb[lb-i-1] - '0';
for (int i = 0; i < la; i++) {
for (int j = 0; j < lb; j++) {
c[i+j] += a[i] * b[j];
c[i+j+1] += c[i + j] / 10;
c[i+j] %= 10;
}
}
if (c[lc] > 0) lc++;
while (c[lc-1] == 0 && lc > 1) lc--;
string t = "";
for (int i = lc - 1; i >= 0; i--) t += c[i] + '0';
return t;
}
int main() {
string sa, sb;
cin >> sa >> sb;
cout << func(sa, sb);
return 0;
}
这里空空如也
有帮助,赞一个