1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
from collections import deque
import sys
ans=deque()
n=int(input())
for i in range(n):
tmp=list(sys.stdin.readline().split())
if tmp[0]=='push' : ans.append(int(tmp[1]))
if tmp[0]=='front' :
if len(ans)==0: print(-1)
else: print(ans[0])
if tmp[0]=='back' :
if len(ans)==0: print(-1)
else: print(ans[-1])
if tmp[0]=='size': print(len(ans))
if tmp[0]=='empty':
if len(ans)==0 : print(1)
else :print (0)
if tmp[0]=='pop':
if len(ans)==0: print (-1)
else:
print(ans[0])
ans.popleft()
|
cs |
반응형
'python-algorithm' 카테고리의 다른 글
백준 11651 좌표 정렬하기 2 (0) | 2021.08.24 |
---|---|
백준 10866 덱 (0) | 2021.08.24 |
백준 10824 스택 (0) | 2021.08.24 |
백준 2164 카드 2 (0) | 2021.08.24 |
백준 10814 나이순 정렬 (0) | 2021.08.23 |
댓글