数学黑洞
Time Limit: 1500 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description
Any 4-digit natural number N (N cannot be the same as 4 numbers, such as 1111, 2222, ....9999 is not allowed, and N cannot be 6174), rearrange the 4 numbers that make up the natural number N to form a maximum number When subtracting the minimum number, the maximum number and the minimum number, the difference is still a natural number. Rearrange the numbers of the difference to form a maximum number and a minimum number. When the maximum number and the minimum number are subtracted, the difference is still a natural number. Repeat until the difference is a mysterious number 6174 (mathematical black hole).
Input
There are multiple groups of input data, each group occupies a row, and each row contains a 4-digit natural number N. Input files until EOF!
Output
For each set of input, the output has 2 lines. The first line is all the differences, separated by spaces, and there are spaces after the last number; the second line is the number of differences.
Sample Input
1000
1500
3000
Sample Output
999 8991 8082 8532 6174
5
5085 7992 7173 6354 3087 8352 6174
7
2997 7173 6354 3087 8352 6174
6
Hint
Source
zlh
package sdut;
import java.util.Scanner;
//import java.util.Arrays;
class heidong{
int n;
final int mm = 4;
heidong(int n){
this.n = n;
}
int a[] = new int[mm];
void sort(){
int t;
for(int i = 0; i < mm - 1; i++){
for(int j = 0; j < mm - i - 1; j++){
if(a[j] > a[j+1]){
t = a[j];
a[j] = a[j + 1];
a[j+1] = t;
}
}
}
}
void fenjie(){
int i = 0;
while(n > 0){
a[i++] = n % 10;
n /= 10;
}
}
}
public class Main {
public static void main(String[] args) {
Scanner ss = new Scanner(System.in);
int n;
while(ss.hasNextInt()){
n = ss.nextInt();
}
ss.close();
}
}