https://www.acmicpc.net/problem/28279
28279번: 덱 2
첫째 줄에 명령의 수 N이 주어진다. (1 ≤ N ≤ 1,000,000) 둘째 줄부터 N개 줄에 명령이 하나씩 주어진다. 출력을 요구하는 명령은 하나 이상 주어진다.
www.acmicpc.net


import sys
from collections import deque
N= int(sys.stdin.readline().rstrip())
deq = deque()
for i in range(N):
command = list(map(int, sys.stdin.readline().rstrip().split()))
if command[0] == 1 :
deq.appendleft(command[1])
elif command[0] == 2 :
deq.append(command[1])
elif command[0] == 3 :
print(deq.popleft() if deq else -1)
elif command[0] == 4 :
print(deq.pop() if deq else -1)
elif command[0] == 5 :
print(len(deq))
elif command[0] == 6 :
print(1 if not deq else 0)
elif command[0] == 7 :
print(deq[0] if deq else -1)
elif command[0] == 8 :
print(deq[-1] if deq else -1)
'CT' 카테고리의 다른 글
[Python] 소수 판별 방법, 에라토스테네스의 체 (0) | 2023.09.07 |
---|---|
[Python] 백준 11866번 : 요세푸스 문제 0 파이썬 (0) | 2023.09.06 |
[Python] 백준 2164번 : 카드2 파이썬 (0) | 2023.09.06 |
[Python] 백준 18258번 : 큐 2 파이썬 (0) | 2023.09.06 |
[Python] 백준 12789번 : 도키도키 간식드리미 파이썬 (0) | 2023.09.06 |
댓글