[SWEA] 5356. 의석이의 세로로 말해요 [D3]
📚 문제
입력된 문자열 중 문자열의 앞부터 열 순서대로 순차적으로 출력하는 문제이다.
문자열의 앞을 출력할 문자열에 하나씩 더해주고 제거한다.
문자열이 더 이상 존재하지 않다면 조건문으로 넘어간다.
모든 문자열이 없는 걸 확인하기 위해 cnt 변수를 활용해 출력한 문자열이 있는지 확인해준다.
📒 코드
T = int(input())
for tc in range(1, 1+T):
arr = [list(input()) for _ in range(5)]
result = ''
while True:
cnt = 0
for i in range(5):
if len(arr[i]):
result += arr[i][0]
del arr[i][0]
cnt += 1
if cnt == 0: break
print(f'#{tc} {result}')
🔍 결과
deque로 queue 자료구조를 활용해 풀어본다.
📒 코드
# deque 활용
from collections import deque
T = int(input())
for tc in range(1, 1+T):
arr = [deque(input()) for _ in range(5)]
result = ''
while True:
cnt = 0
for i in range(5):
if len(arr[i]):
result += arr[i].popleft()
cnt += 1
if cnt == 0: break
print(f'#{tc} {result}')
🔍 결과
예상과 다르게 실행시간은 더 길어졌다.. 그래도 deque를 한 번 활용해보았다.
Author And Source
이 문제에 관하여([SWEA] 5356. 의석이의 세로로 말해요 [D3]), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@yunhlim/SWEA-5356.-의석이의-세로로-말해요-D3저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)