Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. char s[1000001];
  8.  
  9. int k , vf , elim , st[1000001];
  10.  
  11. int main()
  12.  
  13. {
  14.  
  15.    cin >> k;
  16.  
  17.    cin.get();
  18.  
  19.    cin.getline(s , 1000000);
  20.  
  21.    int n = strlen(s);
  22.  
  23.    int i = 0;
  24.  
  25.    while(i < n)
  26.  
  27.    {
  28.  
  29.        if(vf == 0)
  30.  
  31.        {
  32.  
  33.            vf ++;
  34.  
  35.            st[vf] = int(s[i] - 'a' + 1);
  36.  
  37.        }
  38.  
  39.        else
  40.  
  41.        {
  42.  
  43.            while(st[vf] > int(s[i] - 'a' + 1) && elim < k && vf)
  44.  
  45.            {
  46.  
  47.                elim ++;
  48.  
  49.                vf --;
  50.  
  51.            }
  52.  
  53.            vf ++;
  54.  
  55.            st[vf] = int(s[i] - 'a' + 1);
  56.  
  57.        }
  58.  
  59.        i ++;
  60.  
  61.    }
  62.  
  63.    for(int i = 1 ; i <= n - k ; i ++)
  64.  
  65.        cout << char(st[i] - 1 + 'a');
  66.  
  67.    return 0;
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement