Advertisement
DiegoDF

Untitled

Jun 24th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <stack>
  2. #include <iostream>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     stack<char> pilha;
  9.     string s, res;
  10.     int n, tot;
  11.     while((cin >> n >> n) && n)
  12.     {
  13.         cin >> s;
  14.         tot = 0;
  15.         for(int i = 0; s[i] != '\0'; i++)
  16.         {
  17.              while(!pilha.empty() && s[i] > pilha.top() && tot < n)
  18.                 tot++, pilha.pop();
  19.              pilha.push(s[i]);
  20.         }
  21.         while(tot < n)
  22.         {
  23.             pilha.pop();
  24.             tot++;
  25.         }
  26.         res = "";
  27.         while(!pilha.empty())
  28.             res += pilha.top(), pilha.pop();
  29.         reverse(res.begin(), res.end());
  30.         cout << res << endl;
  31.     }
  32.  
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement