给定两个正整数(可能很大,超过long long 长度
#include <iostream> #include <vector> using namespace std; vector<int> a, b, c; void add () { int t = 0; for (int i = 0; i < a.size() || i < b.size() || t; i++) { if (i < a.size()) t += a[i]; if (i < b.size()) t += b[i]; c.push_back(t % 10); t /= 10; } } 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'); add(); for (int i = c.size() - 1; i >= 0; i--) cout << c[i]; return 0; }
),计算它们的和。 标签:高精度,int,back,long,--,加法,push,size From: https://www.cnblogs.com/leetothemoon/p/16939683.html