(1)返回string的长度最大为num1.size() + num2.size();
(2)每次乘法后, carry + multi + str[pos] 的值;
(3)整个过程模拟数字乘法;
(4)最后字串头去除‘0’。
string multiply(string num1, string num2) {
string str(num1.size()+num2.size(),'0');
for(int i=num1.size()-1;i>=0;i--){
int carry=0;
for(int j=num2.size()-1;j>=0;j--){
int multi = (num1[i]-'0')*(num2[j]-'0');
int add = carry + multi+(str[i+j+1]-'0');
str[i+j+1] = '0' + (add%10);
carry = add/10;
}
str[i] = '0'+carry;
}
int i=0;
while(1) {
if(str[0] == '0' && i < str.size()-1)
str.erase(str.begin());
else
break;
}
return str;
}