Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 분할정복
- 다익스트라
- DP
- 플로이드-워셜
- 구현
- 자료구조
- GROUP BY
- 수학
- 브루트포스
- BFS
- 서브쿼리
- 그래프 이론
- 다이나믹프로그래밍
- 다시
- 시뮬레이션
- 재귀
- 에라토스테네스의 체
- MST
- 백트래킹
- DFS
- 그리디
- 다이나믹 프로그래밍
- 크루스칼
- 트리
- join
- 그래프 탐색
- 투포인터
- 우선순위큐
- 해시
- 누적합
Archives
- Today
- Total
기록하고 까먹지 말기
10866 본문
날짜 : 2022. 12. 19
사용 언어 : python
문제

코드
import sys
n = int(sys.stdin.readline())
d = list()
for _ in range(n):
temp = str(sys.stdin.readline().rstrip())
if temp[:3] == "pus":
a, b = temp.split()
b = int(b)
if a == "push_front":
d.insert(0, b)
elif a == "push_back":
d.append(b)
else:
if temp == "front":
if len(d) == 0: print(-1)
else: print(d[0])
elif temp == "back":
if len(d) == 0: print(-1)
else: print(d[-1])
elif temp == "size":
print(len(d))
elif temp == "empty":
if len(d): print(0)
else: print(1)
elif temp == "pop_front":
if len(d) == 0: print(-1)
else:
print(d[0])
del d[0]
elif temp == "pop_back":
if len(d) == 0: print(-1)
else:
print(d[-1])
del d[-1]
풀이
- 조건에 맞게 deque 를 구현하는 문제였다.
알게된 점
- split() 하는 지점을 약간 헷갈리는 바람에 시간을 허비했다.
참고 사이트
-