본문 바로가기
Beakjoon&프로그래머스/파이썬

[백준/파이썬] 9047번 6174

by 현장 2024. 6. 28.

-Code

for _ in range(int(input())):
    n = int(input())
    res = 0
    while n != 6174:
        temp = list(str(n))
        n = int("".join(sorted(temp, reverse=True))) - int("".join(sorted(temp)))
        res += 1

        if n < 1000:
            n = int(str(n) + "0" * (4 - len(str(n))))
    print(res)

n이 1000보다 작은 경우를 생각안해서 틀렸었습니다.