Algorithm
[BAEKJOON] 1874번: 스택 수열
Y06
2021. 9. 30. 20:11
1874번 문제이다.
사진을 누르면 문제로 이동한다.
문제는 Python언어로 구현하였다.
import sys
input = sys.stdin.readline
#입력값 N
N = int(input())
#스택
stack = []
#스택에 넣는 값
count = 1
#결과를 모으는 리스트
result = []
for i in range(N):
#값 입력
num = int(input())
#num값까지 스택에 push
while count <= num:
stack.append(count)
result.append('+')
count += 1
#스택 맨 위에 있는 값이 num이면 pop
if stack[-1]==num:
stack.pop()
result.append('-')
else:
print("no")
exit(0)
for i in result:
print(i)