zoukankan      html  css  js  c++  java
  • 43. Multiply Strings

    string multiply(string num1, string num2) {
        if (num1 == "0" || num2 == "0") return "0";
        int sa = num1.size();
        int sb = num2.size();
        vector<int> temp(sa + sb, 0);
        for (int i = sa - 1; i >= 0; i--) {
            int a = num1[i] - '0';
            for (int j = sb - 1; j >= 0; j--) {
                int b = num2[j] - '0';
                int product = a*b; 
                int carry = (temp[j + i + 1] + product) / 10;
                temp[j + i + 1] = (temp[j + i + 1]+product) % 10;
                int x = 0;
                while (carry) {
                    int p = temp[j + i - x] + carry;
                    temp[j + i - x] = p % 10;
                    carry = p / 10;
                    x++;
                }
            }
        }
        while (temp[0] == 0) temp.erase(temp.begin());
        string res;
        for (int i = 0; i < temp.size(); i++) {
            res += to_string(temp[i]);
        }
        return res;
    }

  • 相关阅读:
    SQL查询
    SQL语句
    SQL语句
    查询设计分析
    数据库引擎调整顾问
    详解执行计划
    详解索引连接类型
    查询开销
    利用SQL Profiler处理开销较大的查询
    状压dp的题目列表 (一)
  • 原文地址:https://www.cnblogs.com/hustlx/p/5255722.html
Copyright © 2011-2022 走看看