๐งฎ PS
๋ฐฑ์ค (boj) 10845 ํ์ด์ฌ - ํ
Newmon
2020. 3. 23. 21:32
๋ฌธ์ ๋งํฌ : https://www.acmicpc.net/problem/10845
10845๋ฒ: ํ
์ฒซ์งธ ์ค์ ์ฃผ์ด์ง๋ ๋ช ๋ น์ ์ N (1 ≤ N ≤ 10,000)์ด ์ฃผ์ด์ง๋ค. ๋์งธ ์ค๋ถํฐ N๊ฐ์ ์ค์๋ ๋ช ๋ น์ด ํ๋์ฉ ์ฃผ์ด์ง๋ค. ์ฃผ์ด์ง๋ ์ ์๋ 1๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ๊ณ , 100,000๋ณด๋ค ์๊ฑฐ๋ ๊ฐ๋ค. ๋ฌธ์ ์ ๋์์์ง ์์ ๋ช ๋ น์ด ์ฃผ์ด์ง๋ ๊ฒฝ์ฐ๋ ์๋ค.
www.acmicpc.net
ํ๋ ์คํ๊ณผ ๋ฐ๋๋๋ ๊ฐ๋ ์ด๋ผ๊ณ ์๊ฐํ๋ฉด ๋๋ค. ํ๋ ๋จผ์ ๋ค์ด์จ๊ฒ์ ๋จผ์ ๊บผ๋ด๋ ์ ์ ์ ์ถ
์คํ์ ํ์ ์ ์ถ์ด๋ค.
import sys
input = sys.stdin.readline
N = int(input())
arr = []
for i in range(N):
command = input().rstrip()
if 'push' in command :
a,num = command.split()
arr.append(num)
elif 'pop' in command :
if len(arr) == 0 : print(-1)
else : print(arr.pop(0))
elif 'size' in command : print(len(arr))
elif 'empty' in command : print(1 if len(arr)==0 else 0)
elif 'front' in command : print(-1 if len(arr)==0 else arr[0])
elif 'back' in command : print(-1 if len(arr)==0 else arr[-1])