728x90
9783번: Easy Encryption
In order to send a secret message to your friend, you invent an original method to encrypt the message. The encryption rule is quite simple. A letter is replaced with 2-digit number. Each letter has its corresponding number as the following: a = 01, b = 02
www.acmicpc.net
문제 풀이
입력값을 문제의 규칙에 따라 변환해 출력해주는 문제이다.
- 알파벳은 소문자 a부터 z까지 01 ~ 26으로 변환해 출력해준다.
- 대문자는 A ~ Z 까지 27 ~ 52로 변환해 출력해준다.
- 숫자는 숫자 앞에 "#"을 붙여 출력해준다.
- 나머지는 그대로 출력한다.
정답 코드
alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in input() :
if alpha.find(i) >= 0 : print(str(alpha.find(i) + 1).zfill(2), end = "")
elif i >= "0" and i <= "9" : print(f"#{i}", end = "")
else : print(i, end = "")
728x90
'Algorithm > PS' 카테고리의 다른 글
[BOJ/백준] 9848 - Gift [python] (0) | 2023.03.28 |
---|---|
[BOJ/백준] 9838 - XMAX [python] (0) | 2023.03.27 |
[BOJ/백준] 9776 - Max Volume [python] (0) | 2023.03.27 |
[BOJ/백준] 9773 - ID Key [python] (0) | 2023.03.27 |
[BOJ/백준] 9771 - Word Searching [python] (0) | 2023.03.27 |