Algorithms

problem A. Speaking in Tongues

Roien 2015. 4. 3.
반응형



1. problem A. Speaking in Tongues


1) 문제 정의
https://code.google.com/codejam/contest/1460488/dashboard#s=p0


2. Solution (in Python)


# translator.py

translation_tbl = {'a' : 'y',
'b' : 'h',
'c' : 'e',
'd' : 's',
'e' : 'o',
'f' : 'c',
'g' : 'v',
'h' : 'x',
'i' : 'd',
'j' : 'u',
'k' : 'i',
'l' : 'g',
'm' : 'l',
'n' : 'b',
'o' : 'k',
'p' : 'r',
'q' : 'z',
'r' : 't',
's' : 'n',
't' : 'w',
'u' : 'j',
'v' : 'p',
'w' : 'f',
'x' : 'm',
'y' : 'a',
'z' : 'q',
' ' : ' '}



in_file = open("./input.txt", 'r')
out_file = open("./output.txt", 'w')

num_test = int(in_file.readline())


for test_cnt in range(num_test):
test_values = in_file.readline()
output = []
for elem_i in test_values:
if ('\n' != elem_i):
output.append(translation_tbl[elem_i])
print('Case #%d%%:' % (test_cnt + 1), end=" "),print("".join(output))
out_file.write('Case #')
out_file.write(str(test_cnt + 1))
out_file.write(': ')
out_file.write("".join(output))
out_file.write("\n")


반응형

댓글