백준 15828 router

김민영·2022년 12월 29일
0

알고리즘

목록 보기
14/125
import sys
from collections import deque
input = sys.stdin.readline

N = int(input())
queue = deque([])
while True:
    a = int(input())
    if a == -1:
        break

    if a == 0 and len(queue) != 0:
        queue.popleft()
    elif a!=0 and len(queue) != N:
        queue.append(a)

if len(queue) == 0:
    print("empty")
else:
    print(*queue)
  • 출력시 리스트를 띄어쓰기로 출력하려면 print(*list)만 해도 됨!
  • 큐의 최대 길이를 제한해야해서 deque의 maxlen을 설정해줬다. 이렇게 하면 50점이 나오고, 위 코드처럼 일일히 확인하면 100점이 나온다. 무슨차이지...
profile
노션에 1차 정리합니당 - https://cream-efraasia-f3c.notion.site/4fb02c0dc82e48358e67c61b7ce8ab36?v=

0개의 댓글