Boolean XOR Expression
Programming Interview
Hard
5 views
Problem Description
A boolean string s of 0/1 and a boolean string t of 0/1 are provided, same length. Treat them as bits and compute (s XOR t) as a new string. Output it.
Input Format
Two lines: s then t.
Output Format
One line result.
Official Solution
import sys
lines=sys.stdin.read().splitlines()
if len(lines)<2: sys.exit(0)
s=lines[0].strip()
t=lines[1].strip()
L=min(len(s),len(t))
out=[]
for i in range(L):
out.append('0' if s[i]==t[i] else '1')
sys.stdout.write(''.join(out))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!