大数相乘:
#include <iostream>
#include <vector>
#include <string>std::vector<int> multiply(const std::vector<int>& num1, const std::vector<int>& num2) {int n1 = num1.size();int n2 = num2.size();std::vector<int> result(n1 + n2, 0);for (int i = n1 - 1; i >= 0; --i) {int carry = 0;for (int j = n2 - 1; j >= 0; --j) {int sum = num1[i] * num2[j] + result[i + j + 1] + carry;result[i + j + 1] = sum % 10;carry = sum / 10;}result[i] += carry;}// 去除前导零int i = 0;while (i < result.size() && result[i] == 0)++i;if (i == result.size())return {0};return std::vector<int>(result.begin() + i, result.end());
}int main() {std::vector<int> num1 = {1, 2, 3};std::vector<int> num2 = {4, 5, 6};std::vector<int> product = multiply(num1, num2);for (int digit : product) {std::cout << digit;}std::cout << std::endl;return 0;
}