-
백준 10866번 : 덱 (Python, 파이썬) - 자료구조 덱(Deque)카테고리 없음 2019. 1. 14. 23:17
https://www.acmicpc.net/problem/10866
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455class deque:def __init__(self):self.items = []def push_front(self,x):self.items.insert(0,x)def pop_front(self):if len(self.items) == 0:return -1else:return self.items.pop(0)def push_back(self,x):self.items.append(x)def pop_back(self):if len(self.items) == 0:return -1else:return self.items.pop()def size(self):return len(self.items)def empty(self):if len(self.items) == 0:return 1else:return 0def front(self):if len(self.items) == 0:return -1else:return self.items[0]def back(self):if len(self.items) == 0:return -1else:return self.items[-1]D = deque()N = int(input())for _ in range(N):cmd = list(input().split(' '))if cmd[0] == 'push_back':D.push_back(int(cmd[1]))elif cmd[0] == 'push_front':D.push_front(int(cmd[1]))elif cmd[0] == 'pop_front':print(D.pop_front())elif cmd[0] == 'pop_back':print(D.pop_back())elif cmd[0] == 'size':print(D.size())elif cmd[0] == 'empty':print(D.empty())elif cmd[0] == 'front':print(D.front())elif cmd[0] == 'back':print(D.back())cs