Created
July 4, 2016 19:34
-
-
Save andigena/049b2bdb299dba7895a4400311b76f76 to your computer and use it in GitHub Desktop.
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 | |
sys.setrecursionlimit(10000) | |
files = ['A-small-practice.in', 'A-large-practice.in'] | |
def last_word(S, lastw): | |
if S == '': | |
return lastw | |
else: | |
return last_word(S[1:], S[0] + lastw if S[0] >= lastw[0] else lastw + S[0]) | |
def solve(fn): | |
sol = '' | |
with open(fn) as f: | |
next(f) | |
for case, line in enumerate(f, 1): | |
S = line.strip() | |
curr = last_word(S[1:], S[0]) | |
sol += 'Case #{}: {}\n'.format(case, curr) | |
with open(fn + '.sol', 'wt') as f: | |
f.write(sol) | |
print(sol) | |
for fn in files: | |
solve(fn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment