-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP100.java
42 lines (33 loc) · 996 Bytes
/
P100.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package p100_199;
import java.util.Arrays;
import java.util.Scanner;
//accepted
public class P100 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
int x = sc. nextInt();
int contador = 0;
while (contador<7){
if (x==6174)break;
int[] arr = new int[4];
for (int j = 0; j < 4; j++) {
arr[j]=x%10;
x=x/10;
}
Arrays.sort(arr);
int max = 0;
int min = 0;
for (int j = 0; j < 4; j++) {
min = min*10 + arr[j];
max = max*10 + arr[arr.length-1-j];
}
x = max - min;
if (x==0) contador = 7;
contador++;
}
System.out.println(contador);
}
}
}