구현
-
백준 10845 어떻게 풀었나, 큐(Queue) 구현백준 2022. 12. 31. 12:49
코드 import sys N = int(sys.stdin.readline()) stack = [] for i in range(N): cmd = sys.stdin.readline().strip() #push X: 정수 X를 큐에 넣는 연산이다. if "push" in cmd: stack.append(cmd[5:]) #pop: 큐에서 가장 앞에 있는 정수를 빼고, 그 수를 출력한다. 만약 큐에 들어있는 정수가 없는 경우에는 -1을 출력한다. elif cmd == "pop": print(stack.pop(0) if stack else -1) #size: 큐에 들어있는 정수의 개수를 출력한다. elif cmd == "size": print(len(stack)) #empty: 큐가 비어있으면 1, 아니면 0을 출..