-->
当前位置:首页 > 题库

PROGRAMMING:6174 question

Luz5年前 (2021-05-10)题库475
###Task description
```
The famous "6174 black hole" problem is described as follows:
For any 4-bit positive integer n with different digits, the following transformation is carried out on N: sort all the digits of N from large to small to get integer a,
All the numbers are arranged from small to large to get the integer B, then A-B is taken as the new 4-bit integer n, and the above transformation operation is repeated until 6174 is obtained,
Then it goes into the 7641-1476 = 6174 trap (black hole).
(in all calculations, if you get a number of less than 4 digits, you can add 0 to the left of the integer to make up for 4 digits.)
For example, starting from 9998, we can get
(the first transformation) 9998-8999 = 0999
(the second transformation) 9990-0999 = 8991
(the third transformation) 9981-1899 = 8082
(4th transformation) 8820-0288 = 8532
(5th transform) 8532-2358 = 6174
6174-6174 = 6174
After five transformations, 6174 was obtained.
For another example, starting from 1234, we can get
(the first transformation) 4321-1234 = 3087
(the second transformation) 8730-0378 = 8352
(the third transformation) 8532-2358 = 6174
6174-6174 = 6174
After three transformations, 6174 was obtained.
That is to say, for any 4-bit positive integer n with different digits, after several steps of calculation, it will eventually reach 6174 and fall into 6174
The samsara of life! This is the famous 6174 black hole problem in mathematics.
Now you need to write a program to output a four digit number. How many times can you get 6174 by such transformation, for example
Output 3 for input 1234 and 5 for input 9998.
```
###Input format:
The first integer k represents K sets of test data. Next, there are k 4-bit integers.
###Output format:
Each row outputs an integer representing the result of a set of data.
###Input example:
```in
2 1234 9998
```
###Output example:
```out
three
five
```







answer:If there is no answer, please comment