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 |
Tags
- java
- SaaS
- 자료형
- 문자열 숫자 변환
- 11652
- 데이터타입
- 11004
- 리스트
- aws
- IaaS
- 최대공약수
- 유클리드 호제법
- 짝수
- parseInt
- 웹 서버
- 최대공배수
- 2진수
- level1
- IntelliJ
- 백준
- 알고리즘
- algorithm
- 프로젝트 생성
- PaaS
- INT
- 홀수
- valueof
- 온프레미스
- Python
- 프로그래머스
Archives
- Today
- Total
Ga0Lee
[알고리즘] 큐 백준 10845 (Python) 본문
queue 는 선입선출이라는 것을 기억하고 풀었다.
코드
import sys
n = int(sys.stdin.readline())
queue = []
for i in range(n):
command = sys.stdin.readline().split()
if command[0] == 'push' :
queue.insert(0,command[1])
elif command[0] == 'pop' :
if len(queue) == 0:
print(-1)
else :
print(queue.pop())
elif command[0] == 'size' :
print(len(queue))
elif command[0] == 'empty' :
if len(queue) == 0 :
print(1)
else :
print(0)
elif command[0] == 'front' :
if len(queue) == 0 :
print(-1)
else :
print(queue[-1])
elif command[0] == 'back' :
if len(queue) == 0 :
print(-1)
else :
print(queue[0])
입출력
'Algorithm' 카테고리의 다른 글
[알고리즘] 알파벳 개수 백준 10808 (Python) (0) | 2022.01.17 |
---|---|
[알고리즘] 덱 백준 10866 (Python) (0) | 2022.01.16 |
[알고리즘] 괄호 백준 9012 (Python) (0) | 2022.01.14 |
[알고리즘] 스택 백준 10828 (Python) (0) | 2022.01.14 |
[알고리즘] K번째 수 백준 11004 (Python) (0) | 2022.01.14 |