[백준]S4-10845

py_code·2021년 1월 15일
0

백준-실버4

목록 보기
5/7
post-custom-banner

import sys

def size(queue):
    return len(queue)

def empty(queue):
    if len(queue)==0:
        return 1
    else:
        return 0

def push(queue, x):
    queue.append(x)

def pop(queue):
    if empty(queue)==0:
        return queue.pop(0)
    else:
        return -1

def front(queue):
    if empty(queue)==0:
        return queue[0]
    else:
        return -1

def back(queue):
    if empty(queue)==0:
        return queue[-1]
    else:
        return -1

que = []
n = int(input())
for _ in range(n):
    input_s = sys.stdin.readline().rstrip().split()
    order = input_s[0]
    if order == 'push':
        push(que, input_s[1])
    elif order == 'pop':
        print(pop(que))
    elif order == 'size':
        print(size(que))
    elif order == 'empty':
        print(empty(que))
    elif order == 'front':
        print(front(que))
    else:
        print(back(que))
profile
개발자를 꿈꿉니다.
post-custom-banner

0개의 댓글