康复训练
#include <iostream>
#include <vector>
using namespace std;
const int BASE = 1e9;
string A, B;
vector<int> string_to_vector_compress(string a) {
vector<int> ans;
for (int i = a.size() - 1, j = 0, s = 0, t = 1; i >= 0; --i) {
s += (a[i] - '0') * t;
++j, t *= 10;
if (j == 9 || i == 0) {
ans.push_back(s);
j = 0, s = 0, t = 1;
}
}
return ans;
}
vector<int> add_compress(vector<int> &a, vector<int> &b) {
if (a.size() < b.size()) return add_compress(b, a);
vector<int> c;
int t = 0;
for (int i = 0; i < a.size(); ++i) {
t += a[i];
if (i < b.size()) t += b[i];
c.push_back(t % BASE);
t /= BASE;
}
if (t > 0) c.push_back(t);
return c;
}
void print_compress(vector<int> &a) {
printf("%d", a.back());
for (int i = a.size() - 2; i >= 0; --i) printf("%09d", a[i]);
cout << endl;
}
int main() {
cin >> A >> B;
vector<int> a, b;
a = string_to_vector_compress(A), b = string_to_vector_compress(B);
vector<int> c = add_compress(a, b);
print_compress(c);
return 0;
}