일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- mvc
- 우선순위큐
- JPA
- 소수판별
- 인프런
- 그리디 알고리즘
- C#강의
- unity
- 연관관계
- 브루투포스
- spring
- python3
- 프로그래머스
- appendleft
- DP
- deque
- pypy3
- LCM
- 1일1솔
- 합 구하기
- Python
- 파이썬
- BFS
- 누적합
- Java
- popleft
- 완전탐색
- c#
- 백준
- 소수찾기
Archives
- Today
- Total
jae_coding
(백준 자료구조 문제풀이) 10866번 덱 본문
반응형
문제
코드
# popleft 위쪽에 덱 제거
# appendleft 위쪽에 덱 추가
# pop 아래쪽 덱 제거
# append 아래쪽 덱 추가
import sys
from collections import deque
input = sys.stdin.readline
def push_front(lst, num):
lst.appendleft(num)
def push_back(lst, num):
lst.append(num)
def pop_front(lst):
if len(lst) != 0:
print(lst.popleft())
else:
print(-1)
def pop_back(lst):
if len(lst) != 0:
print(lst.pop())
else:
print(-1)
def size(lst):
print(len(lst))
def empty(lst):
if len(lst) != 0:
print(0)
else:
print(1)
def front(lst):
if len(lst) != 0:
print(lst[0])
else:
print(-1)
def back(lst):
if len(lst) != 0:
print(lst[len(lst)-1])
else:
print(-1)
def main():
N = int(input())
deck = deque()
for _ in range(N):
command = list(map(str, input().split()))
if command[0] == "push_front":
push_front(deck, int(command[1]))
elif command[0] == "push_back":
push_back(deck, int(command[1]))
elif command[0] == "pop_front":
pop_front(deck)
elif command[0] == "pop_back":
pop_back(deck)
elif command[0] == "size":
size(deck)
elif command[0] == "empty":
empty(deck)
elif command[0] == "front":
front(deck)
elif command[0] == "back":
back(deck)
main()
반응형
'알고리즘 문제 > 자료구조 문제' 카테고리의 다른 글
(백준 자료구조 문제풀이) 1935번 후위 표기식2 (0) | 2022.07.19 |
---|---|
(백준 자료구조 문제풀이) 1874번 스택 수열 (0) | 2022.07.19 |
(백준 자료구조 문제풀이) 1158번 요세푸스 문제 (0) | 2022.07.18 |
(백준 알고리즘 문제풀이) 18258번 큐 2 (0) | 2022.07.18 |
(백준 자료구조 문제풀이) 9012번 괄호 (0) | 2022.07.18 |
Comments