-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP174.java
57 lines (51 loc) · 1.72 KB
/
P174.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package buclesSimples;
import java.util.Scanner;
//accepted
public class P174 {
static boolean digitosRepetidos(String n){
for (int i = 0; i < n.length()-1; i++) {
for (int j = i+1; j <n.length() ; j++) {
if(n.charAt(i)==n.charAt(j)){
return true;
}
}
}
return false;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int anioNum, anioNum2;
int casos = sc.nextInt();
for (int i = 0; i < casos; i++) {
String anio = sc.next();
String anio2 = anio;
if (digitosRepetidos(anio)){
while (digitosRepetidos(anio)){
anioNum = Integer.parseInt(anio);
anioNum--;
anio= Integer.toString(anioNum);
}
while (digitosRepetidos(anio2)){
anioNum2 = Integer.parseInt(anio2);
anioNum2++;
anio2= Integer.toString(anioNum2);
}
} else {
while (!digitosRepetidos(anio)){
anioNum = Integer.parseInt(anio);
anioNum--;
anio= Integer.toString(anioNum);
}
while (!digitosRepetidos(anio2)){
anioNum2 = Integer.parseInt(anio2);
anioNum2++;
anio2= Integer.toString(anioNum2);
}
}
anioNum=Integer.parseInt(anio)+1;
System.out.print(anioNum);
System.out.print(" " + (Integer.parseInt(anio2)-anioNum));
System.out.println();
}
}
}