diff --git a/H0ngJu/README.md b/H0ngJu/README.md index 2d0adb09..537e6d70 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -7,5 +7,6 @@ | 3차시 | 2024.03.10 | 힙 | [N번째 큰 수](https://www.acmicpc.net/problem/2075) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/156 | | 4차시 | 2024.03.13 | 힙 | [문제집](https://www.acmicpc.net/problem/1766) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/158 | | 5차시 | 2024.03.16 | 구현 | [요세푸스 문제](https://www.acmicpc.net/problem/1158) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/161 | +| 6차시 | 2024.03.19 | 스택 | [오큰수](https://www.acmicpc.net/problem/17298) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/164 | --- diff --git "a/H0ngJu/\354\230\244\355\201\260\354\210\230.py" "b/H0ngJu/\354\230\244\355\201\260\354\210\230.py" new file mode 100644 index 00000000..a9fbaaee --- /dev/null +++ "b/H0ngJu/\354\230\244\355\201\260\354\210\230.py" @@ -0,0 +1,25 @@ +import sys +from collections import * + +def input(): return sys.stdin.readline().strip() +N = int(input()) + +arr = list(map(int, input().split())) +arr.reverse() +answer = [-1 for _ in range(N)] + +id = 0 + +stack = [] +stack.append((id,arr.pop())) + +while arr: + id += 1 + arr_data = arr.pop() + while stack and stack[-1][1] < arr_data: + index, data = stack.pop() + answer[index] = arr_data + stack.append((id, arr_data)) + +for i in answer: + print(i, end=" ") \ No newline at end of file