Skip to content

Commit

Permalink
2024-09-22 스택 수열
Browse files Browse the repository at this point in the history
  • Loading branch information
suhyun113 committed Sep 21, 2024
1 parent c3e3e9e commit 12fb0e1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion suhyun113/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
| 10차시 | 2024.07.13 | 플로이드-워셜 | [플로이드](https://www.acmicpc.net/problem/11404) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/36) |
| 11차시 | 2024.07.16 | BFS | [연구소](https://www.acmicpc.net/problem/14502) | [#39](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/39) |
| 12차시 | 2024.07.24 | 이분 탐색 | [나무 자르기](https://www.acmicpc.net/problem/2805) | [#42](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/42) |
| 16차시 | 2024.09.13 | 그리디 | [동전 0](https://www.acmicpc.net/problem/11047) | [#49](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/49) |
| 16차시 | 2024.09.13 | 그리디 | [동전 0](https://www.acmicpc.net/problem/11047) | [#49](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/49) |
| 17차시 | 2024.09.22 | 스택 | [스택 수열](https://www.acmicpc.net/problem/1874) | [#53](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/53) |
29 changes: 29 additions & 0 deletions suhyun113/스택/17-suhyun113.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 1874 : 스택 수열

n = int(input()) # 수열의 크기
sequence = [int(input()) for _ in range(n)] # 주어진 수열

stack = []
result = []
current = 1 # 스택에 넣을 숫자
possible = True

for num in sequence:
# 현재 숫자보다 수열에서 필요한 숫자가 크거나 같을 때까지 push
while current <= num:
stack.append(current)
result.append('+')
current += 1

# 스택의 최상단이 num과 같다면 pop
if stack and stack[-1] == num:
stack.pop()
result.append('-')
else:
possible = False
break

if possible:
print("\n".join(result))
else:
print("NO")

0 comments on commit 12fb0e1

Please sign in to comment.