python algorithm
백준 1874번: 스택 수열
jsleee
2024. 5. 19. 23:19
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")