#1 PetrP
Snad sem se trefil
public static boolean opakovani(String s) {
int a = 0, b = 0, c = 0, d = 0, e = 0, i = 0;
while (true) {
if (i >= s.length())
break;
int q = Integer.parseInt(s.substring(i, i + 1));
if (q == 1)
a++;
else if (q == 2)
b++;
else if (q == 3)
c++;
else if (q == 4)
d++;
else if (q == 5)
e++;
if (a > 1 || b > 1 || c > 1 || d > 1 || e > 1)
return true;
i++;
}
return false;
}
public static boolean indexOf(String s, char[] data) {
for (int i = 0; i < 8; i++) {
if (s.indexOf(data[i]) != -1)
return true;
}
return false;
}
public static void main(String[] args) {
String smax = "1";
char data[] = { '2', '3', '4', '5', '6', '7', '8', '9' };
int sum = 1;
for (int q = 2; q <= 5; q++) {
data[q - 2] = '0';
smax = String.valueOf(q) + smax;
int max = Integer.parseInt(smax);
sum += q;
for (int i = 1; i <= max; i++) {
String s = String.valueOf(i);
if (indexOf(s, data) || s.length() < q || s.startsWith("1"))
continue;
int temp = 0;
for (int a = 0; a < s.length(); a++)
temp += Integer.parseInt(s.substring(a, a + 1));
if (temp == sum && !opakovani(s))
System.out.println(s);
}
System.out.print("\n");
}
}