-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c98aa55
commit 7ced016
Showing
4 changed files
with
137 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,25 @@ | ||
import sys | ||
|
||
|
||
def remove(_str, index): | ||
if index == len(_str) - 1: | ||
return _str[:-1] | ||
elif index == 0: | ||
return _str[1:] | ||
return _str[:index] + _str[index + 1 :] | ||
|
||
|
||
for line in sys.stdin: | ||
n, d = map(int, line.split()) | ||
|
||
if not n and not d: | ||
break | ||
|
||
prize = input() | ||
current_digit = 0 | ||
|
||
for i in range(d): | ||
index = prize.find(str(current_digit)) | ||
if index == -1: | ||
current_digit += 1 | ||
index = prize.find(str(current_digit)) | ||
prize = remove(prize, index) | ||
|
||
d -= 1 | ||
|
||
print(prize) | ||
prize_initial = input() | ||
prize_final = [] | ||
|
||
for index, digit in enumerate(prize_initial): | ||
if not prize_final: | ||
prize_final.append(digit) | ||
else: | ||
while ( | ||
prize_final | ||
and digit > prize_final[-1] | ||
and n - index + len(prize_final) > n - d | ||
): | ||
prize_final.pop() | ||
if len(prize_final) < n - d: | ||
prize_final.append(digit) | ||
|
||
print(''.join(prize_final)) |
Empty file.
Oops, something went wrong.