Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- int n, k;
- cin >> n >> k;
- char arr[n];
- int freq[125]={};
- if (n==k) {
- cout << endl;
- return 0;
- }
- for (int i=0; i<n; i++) {
- cin >> arr[i];
- freq[arr[i]]++;
- }
- for (int i=97; i<123; i++) {
- while(k>0 && freq[i]>0) {
- freq[i]--;
- k--;
- }
- if(k==0) break;
- }
- string s;
- s = "";
- for (int i=n-1; i>=0; i--) {
- if(freq[arr[i]]>0) {
- freq[arr[i]]--;
- s.insert(s.begin(), arr[i]);
- }
- }
- cout << s;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment