#t44. 三位黑洞数
三位黑洞数
The 3-Digit Kaprekar Number
Problem Description
A "black hole number" (also called a trap number, or the "Kaprekar problem") is a class of numbers with a peculiar transform property. Any three-digit number whose digits are not all the same will, after a finite number of "rearrange and subtract" operations, always reach . The resulting is the 3-digit black hole number. The so-called "rearrange and subtract" operation means: form the largest number and the smallest number obtainable by rearranging the digits of the number, and subtract the smallest from the largest. ( is the 4-digit black hole number.)
For example, for the three-digit number :
1st rearrange-and-subtract: ; 2nd: ; 3rd: ; after that it stays at the black hole number . If the three digits of a three-digit number are all the same, one transform gives .
Given any three-digit number, write a program that outputs the rearrange-and-subtract process.
Input Format
The input gives one three-digit number on one line.
Output Format
Output the rearrange-and-subtract process in the following format:
index: largest number after rearrangement - smallest number after rearrangement = difference
The index starts from and continues until appears on the right side of the equals sign.
Sample Input
123
Sample Output
1: 321 - 123 = 198
2: 981 - 189 = 792
3: 972 - 279 = 693
4: 963 - 369 = 594
5: 954 - 459 = 495
Sample Explanation
The input three-digit number is . First, rearrange the digits into the largest number and the smallest number , subtract to get . Then repeat the operation on : rearrange into the largest number and smallest , subtract to get . Continuing, we get , and finally , and the process ends.
Constraints
The input three-digit number satisfies .