Skip to content

Commit

Permalink
2024-12-25/크게 만들기
Browse files Browse the repository at this point in the history
  • Loading branch information
kokeunho committed Dec 25, 2024
1 parent 2f69915 commit aeb53f1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions kokeunho/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
---
32 changes: 32 additions & 0 deletions kokeunho/그리디 알고리즘/12-kokeunho.java
Original file line number Diff line number Diff line change
@@ -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<Character> 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());

}
}

0 comments on commit aeb53f1

Please sign in to comment.