Skip to content

Instantly share code, notes, and snippets.

@philipjkim
Last active February 7, 2017 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipjkim/e84bd8991ceab05c232cb0bcad4c74a3 to your computer and use it in GitHub Desktop.
Save philipjkim/e84bd8991ceab05c232cb0bcad4c74a3 to your computer and use it in GitHub Desktop.
Google Code Jam 2004 QR Problem 1
import sys
# Problem: https://code.google.com/codejam/contest/2974486/dashboard#s=p0
# Reference: http://codereview.stackexchange.com/a/154360/73051
def main():
submit = False
filename = "A-small-practice"
if submit:
sys.stdout = open(filename + ".out", "w")
msg = ["Bad magician!", set()] + ["Volunteer cheated!"] * 3
lines = [i[:-1] for i in open(filename + ".in")]
for i in range(int(lines[0])):
offset = (i * 10) + 1
a = set(lines[offset + 0 + int(lines[offset + 0])].split(" "))
b = set(lines[offset + 5 + int(lines[offset + 5])].split(" "))
msg[1] = a.intersection(b)
if len(msg[1]) == 1:
msg[1] = msg[1].pop()
print("Case #" + str(i + 1) + ": " + str(msg[len(msg[1])]))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment