lina_os

Untitled

Dec 18th, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cmath>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  11. int n, k;
  12. cin >> n >> k;
  13. char arr[n];
  14. int freq[125]={};
  15. if (n==k) {
  16. cout << endl;
  17. return 0;
  18. }
  19. for (int i=0; i<n; i++) {
  20. cin >> arr[i];
  21. freq[arr[i]]++;
  22. }
  23. for (int i=97; i<123; i++) {
  24. while(k>0 && freq[i]>0) {
  25. freq[i]--;
  26. k--;
  27. }
  28. if(k==0) break;
  29. }
  30. string s;
  31. s = "";
  32. for (int i=n-1; i>=0; i--) {
  33. if(freq[arr[i]]>0) {
  34. freq[arr[i]]--;
  35. s.insert(s.begin(), arr[i]);
  36. }
  37. }
  38. cout << s;
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment