提交时间:2023-10-06 11:28:20

运行 ID: 105431

#include<iostream> #include <cstring> using namespace std; char a[5005] , b[5005]; int a1[5005] , b1[5005] , c[5005]; int main() { gets(a); gets(b); int lena = strlen(a); int lenb = strlen(b); for(int i = 0;i < lena;i++) a1[lena - i] = a[i] - 48; for(int i = 0;i < lenb;i++) b1[lenb - i] = b[i] - 48; int lenc = 1; int x = 0; while(lenc <= lena || lenc <= lenb) { c[lenc] = a1[lenc] + b1[lenc] + x; x = c[lenc] / 10; c[lenc] %= 10; lenc++; } c[lenc] = x; if(c[lenc] == 0) lenc--; for(int i = lenc;i >= 1;i--) cout << c[i]; cout << endl; return 0; }