Skip to content

Commit

Permalink
Create P1084_Erasing_and_Winning.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Boombarm committed Feb 15, 2023
1 parent be37672 commit bd24893
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions cpp/beecrowd/PARADIGMS/P1084_Erasing_and_Winning.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <bits/stdc++.h>

using namespace std;

int main()
{
ios::sync_with_stdio(false);

int N, D;

while(cin >> N >> D && N != 0)
{
string number, new_number = "";

cin >> number;

for(int j = 0; j < N; j++) {
if(D > 0 && number[j] < number[j+1]) {
D--;
while(D > 0 && !new_number.empty() && new_number.back() < number[j+1]) {
new_number.pop_back();
D--;
}
} else {
new_number += number[j];
}
}

while(D-- > 0) {
new_number.pop_back();
}

cout << new_number << "\n";
}
}

0 comments on commit bd24893

Please sign in to comment.