提交时间:2024-08-20 08:36:33
运行 ID: 168235
#include <iostream> #include <cstring> using namespace std; char ch1[1005], ch2[1005]; int a[1005], b[1005], ans[1005]; int main() { int lena, i, in = 0; cin>>lena; for(i=0;i<lena;i++) cin>>ch1[i]>>ch2[i]; for (i = 0; i < lena; i++) a[i] = ch1[lena - 1 - i] - 48; for (i = 0; i < lena; i++) b[i] = ch2[lena - 1 - i] - 48; for (i = 0; i < lena; i++) { ans[i] = a[i] + b[i] + in; in = ans[i] / 10; ans[i] %= 10; } if (in > 0) { ans[lena] = in; lena++; } for (i = lena - 1; i >= 0; i--) cout << ans[i]; return 0; }