728x90
반응형
https://www.acmicpc.net/problem/11655
11655번: ROT13
첫째 줄에 알파벳 대문자, 소문자, 공백, 숫자로만 이루어진 문자열 S가 주어진다. S의 길이는 100을 넘지 않는다.
www.acmicpc.net
문제 해결
- 매우 쉬운 문제이다.
- 사실 리스트 하나 만들고 ['A', 'B', ....] 해놓은 다음 나누기를 해도 되지만 ord(), chr()를 써서 메모리도 깔끔하게 쓰고 함수로 깔끔하게 푸는 것이 베스트이다. (ord()와 chr()을 써볼 수 있는 기회)
CODE
import sys
input = sys.stdin.readline
S = str(input().rstrip())
ans = ''
for spell in S:
if spell.isupper():
num = ord(spell) - ord('A')
real_num = (num+13)%26
x= chr(ord('A')+real_num)
ans += str(x)
elif spell.islower():
num = ord(spell) - ord('a')
real_num = (num+13)%26
x = chr(ord('a')+real_num)
ans += str(x)
else:
ans += spell
print(ans)
728x90
반응형
'알고리즘 > [python] 백준 BOJ' 카테고리의 다른 글
[Python] 백준 2089 -2진수 (0) | 2022.12.20 |
---|---|
[Python] 백준 1373 2진수 8진수 (0) | 2022.12.19 |
[Python] 백준 10820 문자열 분석 (0) | 2022.12.16 |
[Python] 백준 1918 후위 표기식 (0) | 2022.12.15 |
[Python] 백준 1935 후위 표기식2 (0) | 2022.12.14 |
댓글