문제
https://www.acmicpc.net/problem/15828]
15828번: Router
인터넷을 사용하기 위해서는 컴퓨터에 인터넷 회선을 연결하거나 Wi-Fi를 연결해야 한다. 이렇게 연결된 네트워크를 통해 컴퓨터에는 통신이 가능하다. 마음에 드는 노래나 동영상이 있는 곳에
www.acmicpc.net
내 풀이
from collections import deque
import sys
input=sys.stdin.readline
storage=int(input())
buffer=deque()
n=0
while n!=-1:
n=int(input())
if n==0:
buffer.popleft()
else:
if len(buffer)<storage:
if n!=-1:
buffer.append(n)
else:
pass
if buffer:
for i in buffer:
print(i, end=' ')
else:
print("empty")
import sys
input=sys.stdin.readline
-->시간 초과 해결
참고용 다른 사람 풀이
import sys
from collections import *
input=sys.stdin.readline
n=int(input())
q=deque()
while 1:
x=int(input())
if x==-1:
break
if x==0:
q.popleft()
if x and len(q)<n:
q.append(x)
if not q:
print('empty')
else:
while q:
print(q.popleft(),end=' ')
백준 9935 문자열폭발 python (0) | 2021.09.02 |
---|---|
Boj 1991 트리 순회 python (0) | 2021.07.29 |
Boj 큐2 python (0) | 2021.07.23 |
Boj 9012 괄호 python (0) | 2021.07.22 |
Boj 10828 스택 python (0) | 2021.07.19 |
댓글 영역