提交时间:2023-10-10 13:39:47

运行 ID: 106217

#include <iostream> #include <algorithm> #include <cstdio> #include <cmath> using namespace std; const int MAXN = 5e3 + 1e2; int a[MAXN]; int b[MAXN]; int c[MAXN]; void read(int x[]) { string s; cin >> s; int len = s.size(); x[0] = len; for (int i = 0;i <= len - 1;i++) x[len - i] = s[i] - '0'; return ; } void print(int x[]) { bool flag = true; for (int i = x[0];i >= 1;i--) { if (flag && x[i] == 0) continue; flag = false; printf("%d", x[i]); } return ; } void add(int x[], int y[], int z[]) { z[0] = max(x[0], y[0]); for (int i = 1;i <= z[0];i++) { z[i] += x[i] + y[i]; z[i + 1] += z[i] / 10; z[i] %= 10; } while (z[z[0]] != 0) { z[z[0] + 1] += z[z[0]] / 10; z[z[0]] %= 10; z[0]++; } return ; } int main() { read(a); read(b); add(a,b,c); print(c); return 0; }