Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <stdio.h>
- #include <stack>
- #include <list>
- #include <vector>
- #include <cmath>
- #include <algorithm>
- #include <iostream>
- #include <iomanip>
- #include <string.h>
- #include <sstream>
- #include <bitset>
- #include <algorithm>
- #include <queue>
- using namespace std;
- int main(){
- string s;
- int c, d;
- cin >> c >> d;
- while (c+d){
- stack<pair<int, int>> n;
- pair<int, int> a;
- cin >> s;
- for (int i = 0; i < (int) s.size(); ++i) {
- if(!i){
- a.first = s[i]-'0';
- a.second = i;
- n.push(a);
- }else{
- if (s[i]-'0' > n.top().first) {
- while (!n.empty() && d != 0 && s[i]-'0' > n.top().first) {
- s[n.top().second] = 'x';
- n.pop();
- d--;
- }
- a.first = s[i]-48;
- a.second = i;
- n.push(a);
- if (!d) {
- break;
- }
- } else {
- a.first = s[i]-48;
- a.second = i;
- n.push(a);
- }
- }
- }
- while(d!=0){
- s[n.top().second] = 'x';
- n.pop();
- d--;
- }
- for (int i = 0; i < (int) s.size(); ++i) {
- if(s[i] != 'x'){
- cout << s[i];
- }
- }
- cout << '\n';
- cin >> c >> d;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment