// 大整数加法 stringBIGadd(vector<string> nums) { if (nums.size() == 0) return"0"; if (nums.size() == 1)return nums.at(0); string out = ""; int sum = 0; int maxdig = 0; for (auto i : nums) maxdig = MAX(maxdig, i.size()); for (int k = 0; ; k++) { for (auto i = 0; i < nums.size(); i++) { if (nums.at(i).size() > k) sum += nums.at(i).at(nums.at(i).size() - k - 1) - 48; } if (sum == 0 && k>=maxdig) return out; out = (char)(sum % 10 + 48) + out; sum = sum / 10; } }
// 大整数乘法 配套上面的使用 stringBIGtimes(string m, string n) { vector<string> adds; for (int i = n.size() - 1; i >= 0; i--) { stringline=""; int sum = 0; for (int k = m.size() - 1; k >= 0; k--) { sum += (n.at(i) - 48) * (m.at(k) - 48); line = (char)(sum % 10 + 48)+line; sum = sum / 10; } if(sum!=0) line = (char)(sum % 10 + 48)+line; for (int k = n.size()-1; k > i; k--)line = line + '0'; adds.push_back(line); } return BIGadd(adds); }