문제 링크
https://www.acmicpc.net/problem/10866
문제
문제 풀이
import sys
input = sys.stdin.readline
deque = []
n = int(input())
for i in range(n):
command = input().split()
if command[0] == 'push_front':
deque.insert(0, command[1])
elif command[0] == 'push_back':
deque.append(command[1])
elif command[0] == 'pop_front':
if len(deque) == 0:
print(-1)
else:
print(deque.pop(0))
elif command[0] == 'pop_back':
if len(deque) == 0:
print(-1)
else:
print(deque.pop())
elif command[0] == 'size':
print(len(deque))
elif command[0] == 'empty':
if len(deque) == 0:
print(1)
else:
print(0)
elif command[0] == 'front':
if len(deque) == 0:
print(-1)
else:
print(deque[0])
elif command[0] == 'back':
if len(deque) == 0:
print(-1)
else:
print(deque[-1])
'Algorithm > BOJ' 카테고리의 다른 글
[백준] 10809 알파벳 찾기 (파이썬 python) (0) | 2022.01.23 |
---|---|
[백준] 10808 알파벳 개수 (파이썬 python) (0) | 2022.01.23 |
[백준] 10845 큐 (파이썬 python) (0) | 2022.01.23 |
[백준] 10799 쇠막대기 (파이썬 python) (0) | 2022.01.23 |
[백준] 9012 괄호 (파이썬 python) (0) | 2022.01.23 |