Untitled
unknown
plain_text
a year ago
928 B
6
Indexable
#include <iostream> #include <algorithm> using namespace std; int main() { int carry = 0; int tempA, tempB; string res = ""; cin >> tempA; cin >> tempB; while (tempA > 0 || tempB > 0 || carry == 1) { int sum = 0; if (tempA > 0) { sum += tempA % 2; } if (tempB > 0) { sum += tempB % 2; } sum += carry; if (sum>=2) { carry = 1; if (sum == 3) { res += '1'; } else { res += '0'; } } else { res += to_string(sum); carry = 0; } tempA /= 10; tempB /= 10; } reverse(res.begin(), res.end()); if (res.length() == 0) { cout << 0 << endl; } else { cout << stoi(res) << endl; } return 0; }
Editor is loading...
Leave a Comment