Skip to content

Instantly share code, notes, and snippets.

@KarthikMAM
Created July 5, 2017 12:53
Show Gist options
  • Save KarthikMAM/5d61c3c0abec9af5828f2c7567035725 to your computer and use it in GitHub Desktop.
Save KarthikMAM/5d61c3c0abec9af5828f2c7567035725 to your computer and use it in GitHub Desktop.
m = {
'0': '_',
'1': '0',
'2': '1',
'3': '2',
'4': '3',
'5': '4',
'6': '5',
'7': '6',
'8': '7',
'9': '8'
}
for t in range(1, int(input()) + 1):
x = list(input())
change_from = len(x)
for i in range(len(x) - 1, 0, -1):
if x[i] < x[i - 1]:
change_from = i
x[i - 1] = m[x[i - 1]]
print("case #%s: %s" % (t, int(''.join(x[:change_from] + ['9'] * (len(x) - change_from)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment