class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* @param s string字符串 第一个整数
* @param t string字符串 第二个整数
* @return string字符串
*/
string multi(string s, char b) {
string res = "";
if(b == '0')
return "0";
char flag = '0';
while(s.size()) {
auto a = s.back();
s.pop_back();
int num = (a - '0') * (b - '0') + flag - '0';
flag = num / 10 + '0';
num = num % 10;
res = to_string(num) + res;
}
if(flag != '0')
res = to_string(flag - '0') + res;
return res;
}
string plus(string s, string t) {
string res = "";
char flag = '0';
while(s.size() && t.size()) {
auto a = s.back();
s.pop_back();
auto b = t.back();
t.pop_back();
int num = a - '0' + b - '0' + flag - '0';
flag = num / 10 + '0';
num = num % 10;
res = to_string(num) + res;
}
while(s.size()) {
auto a = s.back();
s.pop_back();
int num = a - '0' + flag - '0';
flag = num / 10 + '0';
num = num % 10;
res = to_string(num) + res;
}
while(t.size()) {
auto a = t.back();
t.pop_back();
int num = a - '0' + flag - '0';
flag = num / 10 + '0';
num = num % 10;
res = to_string(num) + res;
}
if(flag != '0')
res = to_string(flag - '0') + res;
return res;
}
string solve(string s, string t) {
// write code here
int tn = t.size();
if(s == "0" || t == "0")
return "0";
string res = "";
for(int i = tn - 1; i >= 0; i--) {
string p = multi(s, t[i]);
// cout << "111+" << p << " ";
for(int j = tn - 1; j > i; j--)
p.push_back('0');
// cout << "p + " << p << " ";
res = plus(res, p);
// cout << "res + " << res << " ";
}
return res;
}
};