#include <iostream> using namespace std; int main(){ string a; string b; cin >> a; cin >> b; string c = ""; int addits = 0; for(int i = a.length()-1; i > -1; i--){ int e = addits; addits = 0; e += ((int)a[i]) - '0'; e += ((int)b[i]) - '0'; c = to_string((e%10)) + c; addits = (e-(e%10))/10; } if(addits > 0){ c = to_string(addits) + c; } cout << c; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <iostream> using namespace std; int main(){ string a; string b; cin >> a; cin >> b; string c = ""; int addits = 0; for(int i = a.length()-1; i > -1; i--){ int e = addits; addits = 0; e += ((int)a[i]) - '0'; e += ((int)b[i]) - '0'; c = to_string((e%10)) + c; addits = (e-(e%10))/10; } if(addits > 0){ c = to_string(addits) + c; } cout << c; } |