백준 14584번: 암호 해독 #Python

ColorlessDia·2024년 9월 13일

algorithm/baekjoon

목록 보기
299/809
import sys

ciphertext = sys.stdin.readline().rstrip()

N = int(sys.stdin.readline())

word_list = [sys.stdin.readline().rstrip() for _ in range(N)]

for i in range(26):
    temp = ''

    for char in ciphertext:
        ascii_code = ((ord(char) + i) % ord('z')) + 1
        
        if ascii_code < ord('a'):
            ascii_code += ord('a') - 1

        temp += chr(ascii_code)
    
    for word in word_list:

        if word in temp:
            print(temp)
            break

0개의 댓글