dietmilk68's blog

By dietmilk68, history, 17 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)))

Full text and comments »

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