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
- 오픽공부법
- 다이나믹프로그래밍
- XML
- ㅂ
- 바텀업
- 이진탐색 #나무 자르기
- 안드로이드주석
- 주석
- topdown
- 메모이제이션
- 오픽점수잘받는방법
- 안드로이드
- 영어말하기
- English
- 오픽노잼
- fibo
- 피보나치수열
- 디피
- dp
- XML주석
- dynamicProgramming
- 영어회화
- stack 스택
- 탑다운
- 이진탐색
- 오픽
- 오픽가격
- 오픽노잼공부방법
- opic
Archives
RUBY
[백준] 큐 본문
출처:: https://www.acmicpc.net/problem/10845
분류:: 큐
1. 문제 이해 및 해결과정
2. 풀이방법
#큐
#https://www.acmicpc.net/problem/10845
import sys
from collections import deque
sys.stdin = open("input.txt","r")
q=deque()
n=int(input())
for i in range(n):
cmd=sys.stdin.readline().rstrip().split()
if cmd[0]=="push":
q.append(cmd[1])
elif cmd[0]=="front":
if q:
print(q[0])
else:
print("-1")
elif cmd[0]=="back":
if q:
print(q[-1])
else:
print("-1")
elif cmd[0]=="pop":
if q:
print(q.popleft())
else:
print("-1")
elif cmd[0]=="size":
print(len(q))
elif cmd[0]=="empty":
if q:
print("0")
else:
print("1")
3. 오답원인
1.시간초과
-> 명령어를 input()으로만 받으면 치간초과가 난다
4. 알게된 점
입력 속도 빠르게 하는 방법
sys.stdin.readline().rstrip().split()
Comments