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
- 그리디
- 수학
- 그래프 탐색
- 누적합
- DFS
- 백트래킹
- MST
- 트리
- 분할정복
- join
- 구현
- 서브쿼리
- 우선순위큐
- 플로이드-워셜
- 해시
- 에라토스테네스의 체
- 다이나믹 프로그래밍
- 재귀
- 자료구조
- 다익스트라
- BFS
- 다시
- 다이나믹프로그래밍
- GROUP BY
Archives
- Today
- Total
기록하고 까먹지 말기
10845 본문
날짜 : 2022. 10. 28
사용 언어 : python
문제
코드
from collections import deque
import sys
n = int(sys.stdin.readline())
q = deque()
for i in range(n):
command = str(sys.stdin.readline().strip())
if command[:4] == "push":
com, num = command.split()
q.append(int(num))
else:
if command == "pop":
if len(q) == 0: print(-1)
else:
tmp = q.popleft()
print(tmp)
elif command == "size": print(len(q))
elif command == "empty":
if len(q) == 0: print(1)
else: print(0)
elif command == "front" :
if len(q) == 0:
print(-1)
else:
print(q[0])
elif command == "back" :
if len(q) == 0:
print(-1)
else:
print(q[-1])
#print(q)
알게된 점
- 큐를 구현하는 기본적인 문제였다.
- 문제 자체는 바로 구현했지만 촬영중에 풀었던거라 천천히 만들었다.
- 알바하면서 공부하는게 쉽진 않은듯..
참고 사이트
-