File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ # sys로 명령 수를 받은 뒤, deque를 통해 비어 있는 큐를 생성한다
2+ # 명령 처리에 필요한 기능을 구현한 뒤, 입력된 명령 수인 a 만큼 for문을 통해 반복한다
3+
4+ import sys
5+ from collections import deque
6+
7+ a = int (sys .stdin .readline ())
8+ deq = deque ()
9+ for _ in range (a ):
10+ b = sys .stdin .readline ().split ()
11+
12+ # deq에 추가
13+ if b [0 ] == 'push' :
14+ deq .append (int (b [1 ]))
15+ # 가장 앞의 수 출력
16+ if b [0 ] == 'pop' :
17+ if deq :
18+ print (deq .popleft ())
19+ else :
20+ print (- 1 )
21+ # 큐에 든 정수 개수 출력
22+ if b [0 ] == 'size' :
23+ print (len (deq ))
24+ # 비었다면 0, 아니면 1
25+ if b [0 ] == 'empty' :
26+ if deq :
27+ print ('0' )
28+ else :
29+ print ('1' )
30+ # 큐의 가장 앞 정수 출력, 정수가 없을 경우 -1 출력
31+ if b [0 ] == 'front' :
32+ if deq :
33+ print (deq [0 ])
34+ else :
35+ print (- 1 )
36+ # 큐의 가장 뒤 정수 출력, 없을 경우 -1 출력
37+ if b [0 ] == 'back' :
38+ if deq :
39+ print (deq [- 1 ])
40+ else :
41+ print (- 1 )
You can’t perform that action at this time.
0 commit comments