boolcmp(vector<int> &a, vector<int> &b) { if (a.size() != b.size()) return a.size() > b.size(); for (int i = a.size() - 1; i >= 0; i -- ) { if (a[i] != b[i]) return a[i] > b[i]; } returntrue; }
vector<int> sub(vector<int> &m, vector<int> &n) { vector<int> res; for (int i = 0, t = 0; i < m.size(); i ++ ) { t += m[i]; if (i < n.size()) t -= n[i]; res.push_back((t + 10) % 10); // 1 if (t < 0) t = -1; else t = 0; } for (;res.size() > 1 && res.back() == 0;) res.pop_back(); // 2 return res; }
intmain() { string a, b; cin >> a >> b; vector<int> m, n; for (int i = a.length() - 1; i >= 0; i -- ) m.push_back(a[i] - '0'); for (int i = b.length() - 1; i >= 0; i -- ) n.push_back(b[i] - '0'); vector<int> res; if (cmp(m, n)) res = sub(m, n); else { res = sub(n, m); cout << '-'; } for (int i = res.size() - 1; i >= 0; i -- ) cout << res[i]; return0; }