From 12fb0e155b082a4c757b8e8bea53e16c807d77e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=88=98=ED=98=84?= Date: Sun, 22 Sep 2024 02:26:36 +0900 Subject: [PATCH] =?UTF-8?q?2024-09-22=20=EC=8A=A4=ED=83=9D=20=EC=88=98?= =?UTF-8?q?=EC=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- suhyun113/README.md | 3 +- .../\354\212\244\355\203\235/17-suhyun113.py" | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 "suhyun113/\354\212\244\355\203\235/17-suhyun113.py" diff --git a/suhyun113/README.md b/suhyun113/README.md index 4acf66a..2525a98 100644 --- a/suhyun113/README.md +++ b/suhyun113/README.md @@ -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) | \ No newline at end of file +| 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) | \ No newline at end of file diff --git "a/suhyun113/\354\212\244\355\203\235/17-suhyun113.py" "b/suhyun113/\354\212\244\355\203\235/17-suhyun113.py" new file mode 100644 index 0000000..a0f62fe --- /dev/null +++ "b/suhyun113/\354\212\244\355\203\235/17-suhyun113.py" @@ -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") \ No newline at end of file