Algorithm/PS

[BOJ/백준] 9783 - Easy Encryption [python]

chanwoong1 2023. 3. 27. 12:31
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