Skip to content

Commit 4e0d073

Browse files
committed
[BOJ] #18258.큐2 / 실버4 / 10분(O)
1 parent fdd6bfc commit 4e0d073

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import sys
2+
from collections import deque
3+
input = sys.stdin.read
4+
output = sys.stdout.write
5+
6+
def queue_operations(N, data):
7+
queue = deque()
8+
results = []
9+
10+
for i in range(1, N+1):
11+
command = data[i].split()
12+
13+
if command[0] == 'push':
14+
X = int(command[1])
15+
queue.append(X)
16+
elif command[0] == 'pop':
17+
if queue:
18+
results.append(str(queue.popleft()))
19+
else:
20+
results.append('-1')
21+
elif command[0] == 'size':
22+
results.append(str(len(queue)))
23+
elif command[0] == 'empty':
24+
results.append('1' if not queue else '0')
25+
elif command[0] == 'front':
26+
if queue:
27+
results.append(str(queue[0]))
28+
else:
29+
results.append('-1')
30+
elif command[0] == 'back':
31+
if queue:
32+
results.append(str(queue[-1]))
33+
else:
34+
results.append('-1')
35+
36+
output("\n".join(results) + "\n")
37+
38+
data = input().splitlines()
39+
N = int(data[0])
40+
queue_operations(N, data)

0 commit comments

Comments
 (0)