전공/백준
10845
yha97
2022. 10. 28. 15:33
날짜 : 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)
알게된 점
- 큐를 구현하는 기본적인 문제였다.
- 문제 자체는 바로 구현했지만 촬영중에 풀었던거라 천천히 만들었다.
- 알바하면서 공부하는게 쉽진 않은듯..
참고 사이트
-