[Baekjoon 2493 / python / 골드5] 탑 import sys n = int(sys.stdin.readline()) # 탑 개수 towerList = list(map(int, sys.stdin.readline().split())) # 탑 목록 result = [0] * n # 결과 리스트 stack = [] # 후보 탑을 저장할 스택 for i in range(n): while stack: if towerList[stack[-1][0]] Algorithm/Stack 2024.03.27
[Baekjoon 2504 / python / 실버4] 스택 import sys n = int(sys.stdin.readline()) stack = [] for _ in range(n): control = sys.stdin.readline().split() c = control[0] if c == 'push': stack.append(int(control[1])) elif c == 'pop': if len(stack) == 0: print(-1) else: print(stack.pop()) elif c == 'size': print(len(stack)) elif c == 'empty': if len(stack) == 0: print(1) else: print(0) elif c == 'top': if len(stack) == 0: print(-1) else: pri.. Algorithm/Stack 2024.03.26