# 题目

For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the second number from the first one. Repeat in this manner we will soon end up at the number `6174` – the black hole of 4-digit numbers. This number is named Kaprekar Constant.

For example, start from `6767`, we’ll get:

Given any 4-digit number, you are supposed to illustrate the way it gets into the black hole.

### Input Specification:

Each input file contains one test case which gives a positive integer N in the range (0,104).

### Output Specification:

If all the 4 digits of N are the same, print in one line the equation `N - N = 0000`. Else print each step of calculation in a line until `6174` comes out as the difference. All the numbers must be printed as 4-digit numbers.

# 题解

## 思路

• 题目不是很难，主要是字符串的处理不要忘了0
• 就是当我们计算出两数只差时，要对不足四位数的前面补足0,再参与下一轮的排序并做差。
• 这点使用Python很方便
• `c = "0" * (4 - len(str(a - b))) + str(a - b)`即可
• 同时a和b的更新，是对c进行排序。Python排序后会返回一个列表，要拼接转为字符串。并且做差之前要再转为整数。
• `b = int("".join(sorted(c)))` 即可

• a 是被减数
• b 是减数
• c 是差

• 减法

## 代码

• 由于使用Python能AC，因此只放了Python的代码。