Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sys import stdin
- from itertools import repeat
- def merge(decks):
- while len(decks)>1:
- left=decks.pop()
- right=decks.pop()
- temp=[]
- while len(left)>0 and len(right)>0:
- if left[0]<right[0]:
- temp.append(left.pop(0))
- else:
- temp.append(right.pop(0))
- temp.extend(left)
- temp.extend(right)
- decks.append(temp)
- temp = []
- for (number,letter) in decks[0]:
- temp.append(letter)
- return "".join(temp)
- decks = []
- for line in stdin:
- (index, list) = line.split(':')
- deck = zip(map(int, list.split(',')), repeat(index))
- decks.append(deck)
- print merge(decks)
Add Comment
Please, Sign In to add comment