Notice
Recent Posts
Recent Comments
Link
나의 개발일지
[백준] 1874 스택 수열 [Python, 파이썬] 본문
- 문제 : https://www.acmicpc.net/problem/1874
- 🔑 스택
- 나열해야 하는 수 보다 현재 숫자가 같거나 작으면 스택에 넣어놓는다. +
- 스택 제일 위의 수가 나열해야 하는 수와 같으면 스택에서 꺼낸다. -
- +, - 를 바로 출력하지 않고 저장해 놓고 수열을 만들 수 있으면 출력을 한다. 끝 ✨
import sys
input = sys.stdin.readline
n = int(input())
numbers = [int(input()) for _ in range(n)]
stack = []
idx = 1
answer = []
for i in numbers:
while idx <= i:
stack.append(idx)
idx += 1
answer.append("+")
if stack[-1] == i:
stack.pop()
answer.append("-")
else:
print("NO")
exit()
for i in answer:
print(i)
'백준' 카테고리의 다른 글
[백준] 2307 도로검문 [Python, 파이썬] (1) | 2024.01.09 |
---|---|
[백준] 1202 보석 도둑 [Python, 파이썬] (0) | 2024.01.05 |
[백준] 1414 불우 이웃 돕기 [Python, 파이썬] (2) | 2024.01.03 |
[백준] 1922 네트워크 연결 [Python, 파이썬] (1) | 2024.01.03 |
[백준] 1747 소수 & 팰린드롬 [Python, 파이썬] (0) | 2024.01.03 |
Comments