From bb24144fff7c68fc741a0c1840ddb2d0a89f17fa Mon Sep 17 00:00:00 2001 From: wwan13 Date: Thu, 2 May 2024 16:30:36 +0900 Subject: [PATCH] =?UTF-8?q?solve=20:=2010845=20=ED=81=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/boj_10845.py | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 python/boj_10845.py diff --git a/python/boj_10845.py b/python/boj_10845.py new file mode 100644 index 0000000..1a7b2ce --- /dev/null +++ b/python/boj_10845.py @@ -0,0 +1,52 @@ +import sys + +input = sys.stdin.readline + + +def solution(n): + queue = [] + + for i in range(n): + cmd = sys.stdin.readline().split() + + if cmd[0] == "push": + queue.insert(0, cmd[1]) + + elif cmd[0] == "pop": + if len(queue) != 0: + print(queue.pop()) + else: + print(-1) + + elif cmd[0] == "size": + print(len(queue)) + + elif cmd[0] == "empty": + if len(queue) == 0: + print(1) + else: + print(0) + + elif cmd[0] == "front": + if len(queue) == 0: + print(-1) + else: + print(queue[len(queue) - 1]) + + elif cmd[0] == "back": + if len(queue) == 0: + print(-1) + else: + print(queue[0]) + + +def display_result(answer): + print(answer) + + +def main(): + n = int(input()) + solution(n) + + +main()