백준 4604번: Steganography #Python

ColorlessDia·2025년 12월 1일

algorithm/baekjoon

목록 보기
743/807
import sys
from string import ascii_uppercase as uppercase

input = sys.stdin.readline

temp = []
char_list = [' '] + list(uppercase) + ['\'', ',', '-', '.', '?']
matched_char = dict(zip(range(31 + 1), char_list))

while True:
    line = input().rstrip()

    if line == '#':
        break

    if line == '*':
        count = len(temp) % 5

        if count != 0:

            for _ in range(5 - count):
                temp.append('0')

        steganography = []
        
        for i in range(0, len(temp), 5):
            binary = int(''.join(temp[i:i + 5]), 2)
            steganography.append(matched_char[binary])

        print(''.join(steganography))
        temp.clear()
        continue

    length = 0

    for char in line:

        if char == ' ':
            length += 1
            continue

        if length == 0:
            continue

        if length % 2 == 0:
            temp.append('1')
        else:
            temp.append('0')
        
        length = 0

0개의 댓글