Skip to content

Commit e7e2be2

Browse files
committed
[BOJ] 10866 덱 (S4)
1 parent 2d38a62 commit e7e2be2

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Local: 260116","url":"/Users/suyeon/Desktop/algorithm/심수연/3주차/260116.py","tests":[{"id":1768545709159,"input":"15\npush_back 1\npush_front 2\nfront\nback\nsize\nempty\npop_front\npop_back\npop_front\nsize\nempty\npop_back\npush_front 3\nempty\nfront","output":"2\n1\n2\n0\n2\n1\n-1\n0\n1\n-1\n0\n3"}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"/Users/suyeon/Desktop/algorithm/심수연/3주차/260116.py","group":"local","local":true}

심수연/3주차/260116.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# https://www.acmicpc.net/problem/10866
2+
3+
import sys
4+
from collections import deque
5+
input = sys.stdin.readline
6+
7+
N = int(input())
8+
9+
deque = deque()
10+
11+
for i in range(N):
12+
command = input().split()
13+
if command[0] == 'push_front':
14+
deque.appendleft(command[1])
15+
elif command[0] == 'push_back':
16+
deque.append(command[1])
17+
elif command[0] == 'pop_front':
18+
if not deque:
19+
print(-1)
20+
else:
21+
print(deque.popleft())
22+
elif command[0] == 'pop_back':
23+
if not deque:
24+
print(-1)
25+
else:
26+
print(deque.pop())
27+
elif command[0] == 'size':
28+
print(len(deque))
29+
elif command[0] == 'empty':
30+
if not deque:
31+
print(1)
32+
else:
33+
print(0)
34+
elif command[0] == 'front':
35+
if not deque:
36+
print(-1)
37+
else:
38+
print(deque[0])
39+
else:
40+
if not deque:
41+
print(-1)
42+
else:
43+
print(deque[-1])

0 commit comments

Comments
 (0)