Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stack>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int main()
- {
- stack<char> pilha;
- string s, res;
- int n, tot;
- while((cin >> n >> n) && n)
- {
- cin >> s;
- tot = 0;
- for(int i = 0; s[i] != '\0'; i++)
- {
- while(!pilha.empty() && s[i] > pilha.top() && tot < n)
- tot++, pilha.pop();
- pilha.push(s[i]);
- }
- while(tot < n)
- {
- pilha.pop();
- tot++;
- }
- res = "";
- while(!pilha.empty())
- res += pilha.top(), pilha.pop();
- reverse(res.begin(), res.end());
- cout << res << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement