알고리즘

[백준] 10798 세로읽기

유노비 2023. 10. 17. 22:47
반응형
import itertools
import sys

input = [word.strip() for word in itertools.islice(sys.stdin, 5)] # 5줄의 input 값을 list 의 각각의 원소로 담기
max_length = max(len(item) for item in input) # 가장 길이가 긴 단어의 길이 찾기
word_list = [i.ljust(max_length, ' ') for i in input] # 가장 길이가 긴 단어보다 짧은 단어의 경우, 오른쪽을 ' '으로 채워주기
result = ''

for i in range(max_length):
    result += word_list[0][i] + word_list[1][i] + word_list[2][i] + word_list[3][i] + word_list[4][i] # 5개의 단어 세로로 읽기

print(result.replace(' ','')) # 공백(' ') 제거하기

반응형