← 返回 microsoft 的题目列表Replace Digit
类型:online_judge
There is a string S representing a positive number consisting of N digits. In one move, you can choose some digit of S that is not equal to 5 and replace it with the digit 5. What is the maximum number that can be obtained after making exactly K moves?
Write a function:
def solution(S, K):
that, given a string S and an integer K, returns a string representing the maximum value that can be obtained after making exactly K moves. If making exactly K moves is impossible, return "IMPOSSIBLE".
Examples:
Given S = "165232" and K = 3, the function should return "565552".
Given S = "183955" and K = 4, the function should return "585555".
Given S = "5567855" and K = 4, the function should return "IMPOSSIBLE".
Constraints:
N is an integer within the range [1..100,000].
K is an integer within the range [0..100,000].
String S is made only of digits (0–9) and does not contain leading zeros.
Example
Input
165232
3