์•Œ๊ณ ๋ฆฌ์ฆ˜

๋ฐฑ์ค€ 10845 ํ ๋ฌธ์ œํ’€์ด

ghtis1798 2021. 3. 26. 12:43

๋ฌธ์ œ์„ค๋ช…2

 

๐Ÿ“Œ๋ฌธ์ œ์„ค๋ช…

๋ฌธ์ œ์„ค๋ช…
์ž…๋ ฅ์˜ˆ์‹œ
์ถœ๋ ฅ์˜ˆ์‹œ

๐Ÿ“Œ๋ฌธ์ œํ’€์ด

์†Œ์Šค์ฝ”๋“œ

import sys

class Queue:
    def __init__(self):
        self.queue = []
    def push(self, x):
        self.queue.append(x)
    def pop(self):
        if len(self.queue) !=0:
            print(self.queue.pop(0))
        else:
            print(-1)
    def size(self):
        print(len(self.queue))
    def empty(self):
        if len(self.queue) == 0:
            print(1)
        else:
            print(0)
    def front(self):
        if len(self.queue) == 0:
            print(-1)
        else:
            print(self.queue[0])
    def back(self):
        if len(self.queue) == 0:
            print(-1)
        else:
            print(self.queue[-1])

n = int(input())
command = [sys.stdin.readline().rstrip().split() for x in range(n)]
queue = Queue()
for cmd in command:
    if len(cmd) == 2:
        queue.push(cmd[1])
    elif cmd[0] == 'front':
        queue.front()
    elif cmd[0] == 'back':
        queue.back()
    elif cmd[0] == 'size':
        queue.size()
    elif cmd[0] == 'pop':
        queue.pop()
    elif cmd[0] == 'empty':
        queue.empty()
    else:
        print('์ž˜๋ชป๋œ ์ž…๋ ฅ์ž…๋‹ˆ๋‹ค.')