/**
* Binary Addition
*
* Description
* Write a program that, given two binary numbers represented as strings, prints
* their sum in binary. The binary strings are comma separated, two per line. The
* final answer should not have any leading zeroes. In case the answer is zero,
* just print one zero i.e. 0
*
* Input
* Your program should read lines from standard input. Each line contains two binary
* strings, separated by a comma and no spaces.
*
* Output
* For each pair of binary numbers print to standard output their binary sum, one
* per line.
*
* Example
* 110011,1010 => 111101
* 11010,00101001 => 1000011
*
* Copyright © 2012-2021 HireVue
*
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.stream.Stream;
import java.nio.charset.StandardCharsets;
public class Main {
/**
* Iterate through each line of input.
*/
while ((line = in.readLine()) != null) {
try {
// String[] inputs = line.split(",");
// int lvalue = Integer.valueOf(inputs[0], 2);
// int rvalue = Integer.valueOf(inputs[1], 2);
// System.out.println(Integer.toBinaryString(lvalue+rvalue));
.of(line.split(","))
.
mapToInt(str
-> Integer.
valueOf(str,
2)) .sum()));
e.
printStackTrace(System.
err); continue;
}
}
}
}
LyoqCiAqIEJpbmFyeSBBZGRpdGlvbgogKiAKICogRGVzY3JpcHRpb24KICogV3JpdGUgYSBwcm9ncmFtIHRoYXQsIGdpdmVuIHR3byBiaW5hcnkgbnVtYmVycyByZXByZXNlbnRlZCBhcyBzdHJpbmdzLCBwcmludHMKICogdGhlaXIgc3VtIGluIGJpbmFyeS4gVGhlIGJpbmFyeSBzdHJpbmdzIGFyZSBjb21tYSBzZXBhcmF0ZWQsIHR3byBwZXIgbGluZS4gVGhlCiAqIGZpbmFsIGFuc3dlciBzaG91bGQgbm90IGhhdmUgYW55IGxlYWRpbmcgemVyb2VzLiBJbiBjYXNlIHRoZSBhbnN3ZXIgaXMgemVybywKICoganVzdCBwcmludCBvbmUgemVybyBpLmUuIDAKICogCiAqIElucHV0CiAqIFlvdXIgcHJvZ3JhbSBzaG91bGQgcmVhZCBsaW5lcyBmcm9tIHN0YW5kYXJkIGlucHV0LiBFYWNoIGxpbmUgY29udGFpbnMgdHdvI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