题解 | #233#
233
https://ac.nowcoder.com/acm/problem/15756
#include <iostream>
#include <string>
using namespace std;
string multiply(const string& s1, const string& s2) {
int len1 = s1.length(), len2 = s2.length();
string result(len1 + len2, '0');
for (int i = len1 - 1; i >= 0; i--) {
for (int j = len2 - 1; j >= 0; j--) {
int num1 = s1[i] - '0', num2 = s2[j] - '0';
int sum = (result[i + j + 1] - '0') + num1 * num2;
result[i + j + 1] = sum % 10 + '0';
result[i + j] += sum / 10;
}
}
int pos = result.find_first_not_of('0');
if (pos != string::npos) {
return result.substr(pos);
}
return "0";
}
int main() {
int t=0;
cin>>t;
while(t--){
string s1, s2;
cin >> s1 >> s2;
string result = multiply(s1, s2);
cout << result << endl;
}
return 0;
}