Created
February 4, 2013 17:30
-
-
Save yasuharu519/4708168 to your computer and use it in GitHub Desktop.
Facebook Hacker Cup Rount1 #2 Security
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def compare(chunk_key1, chunk_key2): | |
answer = [] | |
for key1, key2 in zip(chunk_key1, chunk_key2): | |
for c1, c2 in zip(key1, key2): | |
if c1 == '?' and c2 == '?': | |
answer.append('a') | |
elif c1 == '?': | |
answer.append(c2) | |
elif c2 == '?': | |
answer.append(c1) | |
elif c1 == c2: | |
answer.append(c1) | |
else: | |
return "IMPOSSIBLE" | |
return "".join(answer) | |
def splitToChunk(in_str, m): | |
l = len(in_str) / m | |
return [in_str[i*l:(i+1)*l] for i in xrange(m)] | |
def un_function_g(chunk): | |
item = chunk.pop() | |
chunk.insert(0, item) | |
return chunk | |
def main(): | |
T = int(sys.stdin.readline().rstrip()) | |
for i in xrange(T): | |
m = int(sys.stdin.readline().rstrip()) | |
key1 = sys.stdin.readline().rstrip() | |
key2 = sys.stdin.readline().rstrip() | |
chunk_key1 = splitToChunk(key1, m) | |
chunk_key2 = splitToChunk(key2, m) | |
converted_chunk_key2 = un_function_g(chunk_key2) | |
print("Case #{0:d}: {1:s}".format(i+1, compare( | |
chunk_key1, converted_chunk_key2))) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment