#include <iostream> #include <vector> using namespace std; vector<int> add(vector<int>& A, vector<int>& B) { int t = 0; vector<int> C; for (int i = 0; i < A.size() || i < B.size(); i++) { if (i < A.size()) t += A[i]; if (i < B.size()) t += B[i]; C.push_back(t % 10); t /= 10; } if (t) C.push_back(t); return C; } //判断是否A>=B bool cmp(string& a, string& b) { if (a.size() != b.size()) return a.size() > b.size(); else return a > b; } vector<int> sub(vector<int>& A, vector<int>& B) { int t = 0; vector<int> C; for (int i = 0; i < A.size(); i++) { t = A[i] - t; if (i < B.size()) t -= B[i]; C.push_back((t + 10) % 10); if (t < 0) t = 1; //向高位的借位 else t = 0; } //去除高位前导零 while (C.size() > 1 && C.back() == 0) C.pop_back(); return C; } vector<int> mul(vector<int>& A, vector<int>& B) { vector<int> C(A.size() + B.size(), 0); 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; i + 1 < C.size(); i++) { C[i + 1] += C[i] / 10; C[i] = C[i] % 10; } while (C.size() > 1 && C.back() == 0) C.pop_back(); return C; } void print(vector<int>& res) { for (int i = res.size() - 1; i >= 0; i--) { cout << res[i]; } cout << endl; } int main() { string a, b; cin >> a >> b; vector<int> A, B; for (int i = a.size() - 1; i >= 0; i--) A.push_back(a[i] - '0'); for (int i = b.size() - 1; i >= 0; i--) B.push_back(b[i] - '0'); //加法 vector res_add = add(A, B); print(res_add); //减法 if (cmp(a, b)) { vector res_sub = sub(A, B); print(res_sub); } else { cout << "-"; vector res_sub = sub(B, A); print(res_sub); } //乘法 vector<int> res_mul = mul(A, B); print(res_mul); return 0; }