์ƒˆ์†Œ์‹

๐Ÿงฎ PS

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

  • -

๋ฌธ์ œ ๋งํฌ :https://www.acmicpc.net/problem/10866

 

10866๋ฒˆ: ๋ฑ

์ฒซ์งธ ์ค„์— ์ฃผ์–ด์ง€๋Š” ๋ช…๋ น์˜ ์ˆ˜ N (1 ≤ N ≤ 10,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„๋ถ€ํ„ฐ N๊ฐœ์˜ ์ค„์—๋Š” ๋ช…๋ น์ด ํ•˜๋‚˜์”ฉ ์ฃผ์–ด์ง„๋‹ค. ์ฃผ์–ด์ง€๋Š” ์ •์ˆ˜๋Š” 1๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 100,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. ๋ฌธ์ œ์— ๋‚˜์™€์žˆ์ง€ ์•Š์€ ๋ช…๋ น์ด ์ฃผ์–ด์ง€๋Š” ๊ฒฝ์šฐ๋Š” ์—†๋‹ค.

www.acmicpc.net

 

 

 

import sys
input = sys.stdin.readline
deque = []
n  = int(input())
for i in range(n):
    command = input().rstrip()
    if " " in command :
        a,b = command.split()
        if a == 'push_front' : deque.insert(0,b)
        elif a == 'push_back' : deque.append(b)
    elif "pop_front" == command : 
        if len(deque) == 0 : print(-1)
        else : print(deque.pop(0))
    elif "pop_back" == command : 
        if len(deque) == 0 : print(-1)
        else : print(deque.pop(-1))
    
    elif 'size' == command : print(len(deque))
    elif 'empty' == command :
        if len(deque) == 0 : print(1)
        else : print(0)
    elif 'front' == command :
        if len(deque) == 0 : print(-1)
        else : print(deque[0])
    elif 'back' == command :
        if len(deque) == 0 : print(-1)
        else : print(deque[-1])

 

Contents

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

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