-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunround.txt
47 lines (44 loc) · 1.34 KB
/
runround.txt
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
/*
ID: achyuta2
LANG: JAVA
TASK: runround
*/
import java.io.*;
import java.util.HashSet;
public class runround {
public static void main(String[] args) throws IOException {
BufferedReader f = new BufferedReader(new FileReader("runround.in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("runround.out")),true);
long start = Long.parseLong(f.readLine())+1;
while (true){
if(isRunaround(start)){
out.println(start);
out.close();
return;
}
start++;
}
}
public static boolean isRunaround(long x){
String real = String.valueOf(x);
char[] chars = real.toCharArray();
HashSet<Character> set = new HashSet<>();
for(int i=0; i<real.length(); i++){
set.add(chars[i]);
}
if(set.size()<chars.length||set.contains('0')){
return false;
}
set.clear();
int index =0;
while (set.size()<real.length()){
if(set.contains(chars[index])){
return false;
}
set.add(chars[index]);
index+=Integer.parseInt(String.valueOf(chars[index]));
index = index % chars.length;
}
return index==0;
}
}