Skip to content

Commit

Permalink
Solve Erasing and Winning in python
Browse files Browse the repository at this point in the history
  • Loading branch information
deniscostadsc committed Jul 14, 2024
1 parent c98aa55 commit 7ced016
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 22 deletions.
39 changes: 17 additions & 22 deletions solutions/beecrowd/1084/1084.py
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 removed solutions/beecrowd/1084/WRONG
Empty file.
Loading

0 comments on commit 7ced016

Please sign in to comment.