-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10845.py
More file actions
27 lines (26 loc) · 735 Bytes
/
10845.py
File metadata and controls
27 lines (26 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import sys
from collections import deque
N=int(sys.stdin.readline())
queue=deque()
for i in range(N):
todo=sys.stdin.readline()
if todo[:4]=='push':
queue.append(int(todo.split()[1]))
elif todo.rstrip('\n')=='size':
print(len(queue))
elif todo.rstrip('\n')=='empty':
if len(queue)==0:
print(1)
else: print(0)
elif todo.rstrip('\n')=='pop':
if not queue: # stack이 비어있을 때
print(-1)
else: print(queue.popleft())
elif todo.rstrip('\n')=='front':
if not queue:
print(-1)
else: print(queue[0])
elif todo.rstrip('\n')=='back':
if not queue:
print(-1)
else: print(queue[-1])