代码
#include <iostream>
#include <string>
using namespace std;
string mutile(string s1, string s2) {
int len1 = s1.length();
int len2 = s2.length();
int res_len = len1 + len2;
int* data1 = (int*)malloc(len1 * sizeof(len1));
int* data2 = (int*)malloc(len2 * sizeof(len2));
int* res = (int*)malloc(res_len * sizeof(res_len));
memset(data1, 0, len1 * sizeof(len1));
memset(data2, 0, len2 * sizeof(len2));
memset(res, 0, res_len * sizeof(res_len));
for (int i = len1 - 1, j = 0; i >= 0; i--, j++) {
data1[i] = s1[j] - '0';
}
for (int i = len2 - 1, j = 0; i >= 0; i--, j++) {
data2[i] = s2[j] - '0';
}
for (int i = 0; i < len1; i++) {
for (int j = 0; j < len2; j++) {
res[i + j] += data1[i] * data2[j];
}
}
for (int i = 0; i < res_len; i++) {
if (res[i] > 9) {
res[i + 1] += res[i] / 10;
}
res[i] %= 10;
}
int index = 0;
string res_num = "";
for (int i = res_len-1; i >=0; i--) {
if (res[i] == 0) {
continue;
}
else {
index = i;
break;
}
}
for (int i = index; i >=0; i--) {
res_num += to_string(res[i]);
}
return res_num;
}
int main()
{
string num1;
string num2;
cin >> num1 >> num2;
string result = mutile(num1, num2);
cout << result;
return 0;
}