코딩테스트/Python
[Python] 백준 #11655 - ROT13
yo~og
2022. 5. 14. 13:22
문제
https://www.acmicpc.net/problem/11655
11655번: ROT13
첫째 줄에 알파벳 대문자, 소문자, 공백, 숫자로만 이루어진 문자열 S가 주어진다. S의 길이는 100을 넘지 않는다.
www.acmicpc.net
풀이
ss = list(input())
for i,s in enumerate(ss):
if 'a' <= s <= 'z':
if 'a' <= chr(ord(s)+13) <= 'z':
ss[i] = chr(ord(s)+13)
else:
ss[i] = chr(ord(s)-13)
if 'A' <= s <= 'Z':
if 'A' <= chr(ord(s)+13) <= 'Z':
ss[i] = chr(ord(s)+13)
else:
ss[i] = chr(ord(s)-13)
print(''.join(ss))
13을 더해서 영문자를 넘어가면 13을 빼준다