데이터 코딩랩
백준 1874 파이썬 스택수열 본문
https://www.acmicpc.net/problem/1874
n = int(input())
stack, ans, find = [], [], True
# 숫자 1 부터 시작
now = 1
for _ in range(n):
num = int(input())
# 스택 쌓기 push
while now <= num :
stack.append(now)
ans.append('+')
now +=1
#스택 꺼내기 pop
if stack and stack[-1] == num :
stack.pop()
ans.append('-')
#불가능한 경우
else :
find = False
# 정답 출력
if not find: # 불가능 하다면
print('NO')
else :
for i in ans: #가능하다면
print(i)
참고
'Algorithm > 백준' 카테고리의 다른 글
백준 27866 파이썬 문자와 문자열 (0) | 2025.04.15 |
---|---|
백준 1406 파이썬 에디터 (0) | 2025.03.26 |
백준 9093 파이썬 단어뒤집기 (3) | 2024.09.03 |
백준 10828 스택 파이썬 (1) | 2024.09.03 |
백준 1009 파이썬 분산 처리 (1) | 2024.07.12 |