给定两个非负整数,请你计算它们的值。
#include <iostream> #include <vector> using namespace std; vector<int> a, b, c; void mul () { int m = a.size(), n = b.size(); c = vector<int> (m + n); for (int i = 0; i < a.size(); i++) { for (int j = 0; j < b.size(); j++) { c[i + j] += a[i] * b[j]; } } for (int i = 0, t = 0; i < c.size(); i++) { t += c[i]; c[i] = t % 10; t /= 10; } while (c.size() > 1 && c.back() == 0) c.pop_back(); } int main() { string x, y; cin >> x >> y; for (int i = x.size() - 1; i >= 0; i--) a.push_back(x[i] - '0'); for (int i = y.size() - 1; i >= 0; i--) b.push_back(y[i] - '0'); mul(); for (int i = c.size() - 1; i >= 0; i--) cout << c[i]; return 0; }
标签:高精度,int,back,++,mul,--,乘法,size From: https://www.cnblogs.com/leetothemoon/p/16939702.html