본문 바로가기
Algorithm/baekjoon

[파이썬]baekjoon 4446: ROT13

by 갈잃자 2023. 2. 15.

https://www.acmicpc.net/problem/4446

 

4446번: ROT13

간달프는 여러 종족의 언어를 꽤 오랜 시간 동안 공부했다. 최근에 간달프는 해커들이 사용하는 언어인 ROT13을 공부했다. 이 언어는 영어와 문법이 같지만, 알파벳의 순서를 어떤 규칙을 이용해

www.acmicpc.net


단순 구현문제이지만, 입력을 잘 읽어봐야한다.

 

입력이 여러 줄이 나오므로, 주어진 테스트케이스 외로 준비를 해야함

 

try except문을 이용하여 더이상 입력이 들어오지 않을때를 대비하였음!

while True:
    try:
        t = list(input())
        upper = [0]*len(t)
        for i in range(len(t)):
            if t[i].isupper():
                t[i]=t[i].lower()
                upper[i] = 1
        m = ["a",'i','y','e','o','u','a','i','y']
        j = ["b","k","x","z","n","h","d","c","w","g","p","v","j","q","t","s","r","l","m","f","b","k","x","z","n","h","d","c","w","g"]

        for i in range(len(t)):
            if t[i] in m:
                t[i] = m[m.index(t[i])+3]


            if t[i] in j:
                t[i] = j[j.index(t[i])+10]

        for i in range(len(upper)):
            if upper[i] ==1:
                t[i] = t[i].upper()

        t = ''.join(t)
        print(t)
    except:
        break

댓글