문제
문자열 s는 J, O, I로만 이루어져 있다.
J, O, I를 각각 O, I, J로 변환하여 출력하라.
풀이
trans에 문제에서 주어진 변환규칙을 정의한다.
result에 이 규칙을 사용해 translate() 메세드로 변환한 결과를 담아 출력한다.
코드
import sys
input=sys.stdin.readline
n=int(input())
s=input()
trans=str.maketrans("JOI", "OIJ")
result=s.translate(trans)
print(result)
'BOJ > Python' 카테고리의 다른 글
[BOJ/백준] 30614 - Port Robot (Python) (1) | 2025.01.21 |
---|---|
[BOJ/백준] 3449 - 해밍 거리 (Python) (0) | 2025.01.21 |
[BOJ/백준] 33161 - 鉛筆 2 (Pencils 2) (Python) (0) | 2025.01.21 |
[BOJ/백준] 33178 - Micromasters (Python) (0) | 2025.01.21 |
[BOJ/백준] 11816 - 8진수, 10진수, 16진수 (python) (1) | 2025.01.01 |