From aeb53f1a960b772b2e4efbf80db5718b23edeade Mon Sep 17 00:00:00 2001 From: kokeunho <95072015+kokeunho@users.noreply.github.com> Date: Wed, 25 Dec 2024 16:42:42 +0900 Subject: [PATCH] =?UTF-8?q?2024-12-25/=ED=81=AC=EA=B2=8C=20=EB=A7=8C?= =?UTF-8?q?=EB=93=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kokeunho/README.md | 1 + .../12-kokeunho.java" | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 "kokeunho/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/12-kokeunho.java" diff --git a/kokeunho/README.md b/kokeunho/README.md index 795fa05..15eb65a 100644 --- a/kokeunho/README.md +++ b/kokeunho/README.md @@ -13,4 +13,5 @@ | 9차시 | 2024.11.26 | 다이나믹 프로그래밍 | [계단 오르기](https://www.acmicpc.net/problem/2579) | [#33](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/33) | | 10차시 | 2024.11.30 | 자료구조 | [가운데를 말해요](https://www.acmicpc.net/problem/1655) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/36) | | 11차시 | 2024.12.21 | 그리디 알고리즘 | [회의실 배정](https://www.acmicpc.net/problem/1931) | [#43](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/43) | +| 12차시 | 2024.12.25 | 그리디 알고리즘 | [크게 만들기](https://www.acmicpc.net/problem/2812) | [#45](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/45) | --- diff --git "a/kokeunho/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/12-kokeunho.java" "b/kokeunho/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/12-kokeunho.java" new file mode 100644 index 0000000..836d1ef --- /dev/null +++ "b/kokeunho/\352\267\270\353\246\254\353\224\224 \354\225\214\352\263\240\353\246\254\354\246\230/12-kokeunho.java" @@ -0,0 +1,32 @@ +package org.example; + +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + int k = sc.nextInt(); + String num = sc.next(); + + Stack stack = new Stack<>(); + + int count = 0; + + for(int i = 0; i < n; i++) { + char c = num.charAt(i); + while(!stack.isEmpty() && count < k && stack.peek() < c) { + stack.pop(); + count++; + } + stack.push(c); + } + + StringBuilder result = new StringBuilder(); + for(int i = 0; i < n - k; i++) { + result.append(stack.get(i)); + } + System.out.println(result.toString()); + + } +} \ No newline at end of file