dietmilk68's blog

By dietmilk68, history, 18 months ago, In English

[problem:C]

n = int(input())
for i in range(n):
    s = list(map(int, list(input())))
    for i in reversed(range(len(s))):
        if s == sorted(s):
            break
        to_shift = max(s[:i+1])
        idx_toshift = s.index(to_shift)
        temp = s[i]
        if s[i] == s[idx_toshift]:
            s[i] = min(s[idx_toshift] + 1, 9)
        else:
            s[i] = min(s[idx_toshift]+1, 9)
            s[idx_toshift] = temp


    print("".join(map(str, s)))

  • Vote: I like it
  • -8
  • Vote: I do not like it

| Write comment?
»
18 months ago, # |
  Vote: I like it -10 Vote: I do not like it

DEBUG IT YOURSELF. STOP ASKING OTHERS TO DEBUG 15 LINES OF CODE