Skip to content

Instantly share code, notes, and snippets.

@mtayseer
Created March 22, 2014 00:14
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 mtayseer/9699181 to your computer and use it in GitHub Desktop.
Save mtayseer/9699181 to your computer and use it in GitHub Desktop.
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