-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10845.py
More file actions
40 lines (32 loc) · 1.23 KB
/
10845.py
File metadata and controls
40 lines (32 loc) · 1.23 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
import sys
input = sys.stdin.readline
n = int(input())
que = [] # 리스트로 큐 만듬
for i in range(n):
command = []
command = input().split() # 명령어 입력 받음
if command[0] == 'push': # push 일 때
que.append(int(command[1])) # 뒤에 큐의 뒷자리에 정수 저장
elif command[0] == 'pop': # pop 일 때
if len(que) == 0: # 비어있으면 -1 출력
print(-1)
else:
print(que[0]) # 맨 앞에 있는 정수 출력 후
del que[0] # 맨 앞에 있는 정수 제거
elif command[0] == 'front': # front 일 때
if len(que) == 0:
print(-1)
else:
print(que[0]) # 맨 앞에 있는 정수 출력
elif command[0] == 'back': # back 일 때
if len(que) == 0:
print(-1)
else:
print(que[-1]) # 맨 뒤에 있는 정수 출력
elif command[0] == 'size': # size 일 때
print(len(que)) # 큐의 크기 출력
elif command[0] == 'empty': # empty 일 때
if len(que) == 0: # 비어있으면 1 출력
print(1)
else: # 안 비어있으면 0 출력
print(0)