#include <iostream>
using namespace std;
int main() {
string first,second,result="";
int a,b;
cin >> first;
cin >> second;
int r,i=1,c=0;
int fl = first.length();
int sl = second.length();
if (sl > fl) {
first.swap(second);
fl = first.length();
sl = second.length();
}
while (i<=fl) {
a = first[fl-i]-48;
if (sl-i >= 0){
b = second[sl-i]-48;
} else {
b = 0;
}
r=a+b+c;
if (r>9) {
r=r-10;
c=1;
} else {
c=0;
}
result.insert(0,to_string(r));
i++;
}
cout << result;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #include <iostream> using namespace std; int main() { string first,second,result=""; int a,b; cin >> first; cin >> second; int r,i=1,c=0; int fl = first.length(); int sl = second.length(); if (sl > fl) { first.swap(second); fl = first.length(); sl = second.length(); } while (i<=fl) { a = first[fl-i]-48; if (sl-i >= 0){ b = second[sl-i]-48; } else { b = 0; } r=a+b+c; if (r>9) { r=r-10; c=1; } else { c=0; } result.insert(0,to_string(r)); i++; } cout << result; } |
English