문제 확인하기
2. 정답 코드 (Python, memory: 31256KB, time: 40ms)
letter_to_sequence = {
'a': '2', 'b': '22', 'c': '222', 'd': '3', 'e': '33', 'f': '333',
'g': '4', 'h': '44', 'i': '444', 'j': '5', 'k': '55', 'l': '555',
'm': '6', 'n': '66', 'o': '666', 'p': '7', 'q': '77', 'r': '777',
's': '7777', 't': '8', 'u': '88', 'v': '888', 'w': '9', 'x': '99',
'y': '999', 'z': '9999'
}
number_substitution = {}
substitution_values = input().split(' ')
for i in range(1, 10):
number_substitution[substitution_values[i - 1]] = str(i)
input_message = input()
converted_message_temp = ''
for i in range(len(input_message)):
if i > 0 and letter_to_sequence[input_message[i]][0] in letter_to_sequence[input_message[i - 1]]:
converted_message_temp += '#'
converted_message_temp += letter_to_sequence[input_message[i]]
final_message = ''
for c in converted_message_temp:
if c == '#':
final_message += '#'
else:
final_message += number_substitution[c]
print(final_message)