Advertisement
DevilLord

Untitled

Jun 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. public static void main(String[] args) throws IOException {
  2. Reader sc = new Reader();
  3. int n = sc.nextInt(), k =sc.nextInt();
  4. sc.readLine();
  5. String str = sc.readLine().trim();
  6. int[] count = new int[26];
  7. for(char c : str.toCharArray()) {
  8. count[c-97]++;
  9. }
  10. int idx = 0;
  11. StringBuilder r = new StringBuilder(str);
  12. while(k > 0) {
  13. int times = count[idx];
  14. char c = (char) (idx+97);
  15. if(times == 0) {
  16. idx++;
  17. } else {
  18. for(int i = 0; i < times;i++) {
  19. r.setCharAt(r.indexOf(String.valueOf(c)),' ');
  20. k--;
  21. if(k == 0) {
  22. break;
  23. }
  24. }
  25. }
  26. idx++;
  27. }
  28.  
  29. p(r.toString().replaceAll(" ", ""));
  30. sc.close();
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement