Canadian Computing Competition: 2013 Stage 1, Junior #3, Senior #1
You might be surprised to know that 2013 is the first year since 1987 with distinct digits. The years 2014, 2015, 2016, 2017, 2018, 2019 each have distinct digits. 2012 does not have distinct digits, since the digit 2 is repeated.
Given a year, what is the next year with distinct digits?
Input Specification
The input consists of one integer (), representing the starting year.
Output Specification
The output will be the single integer , which is the next year after with distinct digits.
Sample Input 1
Copy
1987
Output for Sample Input 1
Copy
2013
Sample Input 2
Copy
999
Output for Sample Input 2
Copy
1023
Solution
import java.util.*;
public class Allfactors {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int year = in.nextInt();
int counter = year;
while(true) {
Set<String> thingy = new HashSet<String>();
counter++;
String lol = String.valueOf(counter);
for(int i=0; i < lol.length(); i++ ) {
String add = Character.toString(lol.charAt(i));
thingy.add(add);
}
if(thingy.size() == lol.length()) {
System.out.println(counter);
break;
}
}
}
}