acen's blog

By acen, history, 2 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

»
2 months ago, # |
  Vote: I like it -8 Vote: I do not like it

Auto comment: topic has been updated by acen (previous revision, new revision, compare).

»
2 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