fork download
#include <bits/stdc++.h>
using namespace std;

string addBinary(string a, string b) {
    int lenA = a.length(), lenB = b.length();
    int i = lenA - 1, j = lenB - 1;
    int carry = 0;
    stack<char> out;
    int sum = 0;
    while(i >= 0 || j >= 0){
        if(i >= 0 && j >= 0){
            sum = a[i] - '0' + b[j] - '0' + carry;
            i--;
            j--;
        }else{
            if(i < 0){
                sum = b[j] - '0' + carry;
                j--;
            }
            else{
                sum = a[i] - '0' + carry;
                i--;
            }
        }
        if(sum > 1){
            carry = 1;
        }else{
            carry = 0;
        }
        sum = sum % 2;
        char aChar = '0' + sum;
        out.push(aChar);
    }
    if(carry){
        out.push('1');
    }
    string res = "";
    while(!out.empty()){
        res = res + out.top();
        out.pop();
    }
    return res;
}


int main() {
	cout << addBinary("11", "1");
	return 0;
}
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
100