본문 바로가기
Beakjoon&프로그래머스/파이썬

[백준/파이썬] 4583번 거울상

by 현장 2022. 8. 4.

-Code

mirror = ['b', 'd', 'p', 'q', 'i', 'o', 'v', 'w', 'x']
dic = {'b':'d', 'd':'b', 'p':'q', 'q':'p'}
while 1:
    s = input()
    result = ""

    if s == '#':
        break

    for i in s:
        if i not in mirror:
            result = "INVALID"[::-1]
            break
        if i in dic:
            result += dic[i]
        else:
            result += i
    print(result[::-1])