提交时间:2024-05-05 17:21:41

运行 ID: 145814

#include<bits/stdc++.h> using namespace std; char sa[5005], sb[5005]; int la, lb, lc, a[5005], b[5005], c[5005]; int main() { cin>>sa>>sb; la = strlen(sa); lb = strlen(sb); for (int i = 0; i < la; i++) { a[la - i - 1] = sa[i] - '0'; } for (int i = 0; i < lb; i++) { b[lb - i - 1] = sb[i] - '0'; } lc = la > lb ? la : lb; for (int i = 0; i < lc; i++) { c[i] = a[i] + b[i] + c[i]; if (c[i] > 10) { c[i + 1] = 1; c[i] -= 10; } } if (c[lc] > 0)lc++; for (int i = lc - 1; i >= 0; i--) { cout<<c[i]<<" "; } return 0; }