The problem describes any four-digit number, as long as the numbers on each bit are not identical, there is this rule:
1) The four digits comprising the four digits are arranged from large to small, forming the largest four digits consisting of these four numbers;
2) The four digits comprising the four digits are arranged from small to large, forming the smallest four digits consisting of the four digits (if four are included, the resulting number is less than 0 digits);
3) Ask for two number difference, get a new four digit number (high 0 reserved).
Repeat the above process and the result will be 6174.
For example: 4312 3087 8352 6174, after three transformations, get 6174 input format a four-bit integer, enter a guaranteed four-bit number is not the same output format an integer, indicating how many times this number transformation can get 6174 sample input 4312 sample Output 3
1 Importjava.util.ArrayList;2 Importjava.util.Arrays;3 Importjava.util.Collections;4 Importjava.util.List;5 ImportJava.util.Scanner;6 7 classmain{8 Static intsum;9 Public Static voidMain (string[] args) {TenScanner input =NewScanner (system.in); OneString temp =Input.next (); AStringBuffer s =NewStringBuffer (temp); - while(!s.tostring (). Equals ("6174")){ - Char[] A =s.tostring (). ToCharArray (); the Arrays.sort (a); -s =NewStringBuffer (String.valueof (a)); - inth = Integer.parseint (S.reverse (). toString ())-Integer.parseint (S.reverse (). toString ()); -s =NewStringBuffer (H + ""); + while(S.length ()!=4){ -S.append ("0"); + } Asum++; at } - System.out.println (sum); - - } -}
Algorithm to improve the digital black hole