From d1971b60a273519293c942af47a20ff4cfcc944e Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Tue, 19 Mar 2024 23:50:07 +0900 Subject: [PATCH] 2024-03-19 --- H0ngJu/README.md | 1 + .../\354\230\244\355\201\260\354\210\230.py" | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 "H0ngJu/\354\230\244\355\201\260\354\210\230.py" diff --git a/H0ngJu/README.md b/H0ngJu/README.md index af4ff40e..9829c739 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -3,5 +3,6 @@ | 차시 | 날짜 | 문제유형 | 링크 | 풀이 | | :---: | :--------: | :------: | :-------------------------------------------------------------------------: | :-------------------------------------------------: | | 1차시 | 2024.03.05 | 큐 | [프로세스](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/151 | +| 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