字符串相乘

class Solution {
public:
    typedef long long lint;

    lint sToInt(const string &s) {
        lint ans = 0;
        for (int i = 0; i < s.length(); i++) {
            ans += ((s[i] - '0') * pow(10, (s.length() - i - 1)));
        }
        return ans;
    }

    string iToStr(lint num) {
        if (num == 0) return "0";
        string s;
        while (num) {
            s += ((num % 10) + '0');
            num /= 10;
        }
        reverse(s.begin(), s.end());
        return s;
    }

    string multiply(string num1, string num2) {
        return iToStr(sToInt(num1) * sToInt(num2));
        return "";
    }
};

你可能感兴趣的:(算法,开发语言)