Created
March 22, 2014 00:14
-
-
Save mtayseer/9699181 to your computer and use it in GitHub Desktop.
Solution for Code Jam Problem C https://code.google.com/codejam/contest/dashboard?c=351101#s=p2
This file contains hidden or 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
key_mapping = [ | |
('abc', '2'), | |
('def', '3'), | |
('ghi', '4'), | |
('jkl', '5'), | |
('mno', '6'), | |
('pqrs', '7'), | |
('tuv', '8'), | |
('wxyz', '9'), | |
(' ', '0'), | |
] | |
translation_table = {'\n': '\n'} | |
for ascii, key in key_mapping: | |
for c in ascii: | |
translation_table[c] = (ascii.index(c)+1) * key | |
lines = open('C-large-practice.in').readlines()[1:] | |
with open('C-large-practive.out', 'w') as out: | |
for i, line in enumerate(lines): | |
result = [] | |
for c in line: | |
if result and translation_table[c][0] == result[-1][0]: | |
result.append(' ') | |
result.append(translation_table[c]) | |
out.write('Case #%d: %s' % (i+1, ''.join(result))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment