https://www.acmicpc.net/problem/1874
해설
"""
1 2 3 4 (PUSH) STACK:
1 2 (POP) STACK: 4 3
1 2 5 6 (PUSH) STACK:
1 2 5 (POP) STACK: 4 3 6
1 2 5 7 8 (PUSH) STACK:
(POP) STACK: 4 3 6 8 7 5 2 1
"""
count = 1
n = int(input())
stack = []
ans = []
define = True
for _ in range(n):
num = int(input())
while count <= num:
stack.append(count)
ans.append('+')
count += 1
if stack[-1] == num:
stack.pop()
ans.append('-')
else:
define = False
if define == True:
for c in ans:
print(c)
else:
print("NO")
'python algorithm' 카테고리의 다른 글
백준 1158: 오세푸스 문제 (0) | 2024.05.30 |
---|---|
python 함수 모음 (0) | 2024.05.18 |
백준 10828번: 스택 (0) | 2024.05.18 |