์ƒˆ์†Œ์‹

๐Ÿงฎ PS

๋ฐฑ์ค€ (boj) 10845 ํŒŒ์ด์ฌ - ํ

  • -

๋ฌธ์ œ ๋งํฌ : 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])
Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.