-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp174.java
58 lines (51 loc) · 1.69 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
58
package com.caiomed03.aceptaelreto;
import java.util.Scanner;
public class p174 {
public static boolean hasRepeatedDigits(int a) {
String aux = String.valueOf(a);
for (int i = 0; i < aux.length(); i++) {
for (int j = i + 1; j < aux.length(); j++) {
if (aux.charAt(i) == aux.charAt(j)) {
return true;
}
}
}
return false;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int casosPrueba = sc.nextInt();
for (int i = 0; i < casosPrueba; i++) {
int n = sc.nextInt();
int primerAño = 0, ultimoAño = 0;
if (hasRepeatedDigits(n)) {
for (int j = n; true; j--) {
if (!hasRepeatedDigits(j)) {
primerAño = j + 1;
break;
}
}
for (int j = primerAño; true; j++) {
if (!hasRepeatedDigits(j)) {
ultimoAño = j - 1;
break;
}
}
} else {
for (int j = n; true; j--) {
if (hasRepeatedDigits(j)) {
primerAño = j + 1;
break;
}
}
for (int j = primerAño; true; j++) {
if (hasRepeatedDigits(j)) {
ultimoAño = j - 1;
break;
}
}
}
System.out.println(primerAño + " " + (ultimoAño - primerAño + 1));
}
}
}