알고리즘

<백준> 10845번 파이썬 알고리즘

changha. 2021. 7. 11. 16:12
import sys

n = int(sys.stdin.readline())
q = []
for _ in range(n):
  m = sys.stdin.readline().split()

  if m[0] == 'push':
      q.append(m[1])
  elif m[0] == "pop":
      if len(q) != 0:
        print(q.pop(0))
      else:
        print(-1)
  elif m[0] == "size":
    print(len(q))
  elif m[0] == "front":
    if len(q) != 0:
        print(q[0])
    else:
        print(-1)
  elif m[0] == "back":
    if len(q) != 0:
        print(q[-1])
    else:
        print(-1)
  elif m[0] == 'empty':
    if len(q) != 0:
      print(0)
    else:
      print(1)