Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) throws IOException {
- Reader sc = new Reader();
- int n = sc.nextInt(), k =sc.nextInt();
- sc.readLine();
- String str = sc.readLine().trim();
- int[] count = new int[26];
- for(char c : str.toCharArray()) {
- count[c-97]++;
- }
- int idx = 0;
- StringBuilder r = new StringBuilder(str);
- while(k > 0) {
- int times = count[idx];
- char c = (char) (idx+97);
- if(times == 0) {
- idx++;
- } else {
- for(int i = 0; i < times;i++) {
- r.setCharAt(r.indexOf(String.valueOf(c)),' ');
- k--;
- if(k == 0) {
- break;
- }
- }
- }
- idx++;
- }
- p(r.toString().replaceAll(" ", ""));
- sc.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement