// CodeEval Following Integer
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.*;
class MainCodeEval {
public static void main(String[] args) {
next_number.main(args);
}
}
class next_number {
private static PrintStream out;
public static void main(String[] args) {
boolean LOCAL_TEST = false;
// LOCAL_TEST = true;// comment it before submitting
out = System.out;
if (LOCAL_TEST)
CodeEvalGetInput("e:\\zin2.txt");
else
CodeEvalGetInput(args[0]);
}
public static void CodeEvalGetInput(String arg) {
try {
File file = new File(arg);
BufferedReader in = new BufferedReader(new FileReader(file));
String line;
while ((line = in.readLine()) != null) {
// Process line of input Here
Process(line);
}
} catch (IOException e) {
System.out.println("File Read Error: " + e.getMessage());
}
}
private static void Process(String line) {
String s = line;
int N = Integer.valueOf(s);
int[] cnt = new int[10];
int m = N;
while (m > 0) {
int r = m % 10;
cnt[r] += 1;
m = m / 10;
}
int ans = 0;
for (int i = N + 1; i < 10000000; i++) {
boolean valid = true;
int[] cntAns = new int[10];
int X = i;
for (int j = 1; j <= 9; j++) {
while (X > 0) {
int r = X % 10;
cntAns[r] += 1;
X = X / 10;
}
if (cntAns[j] != cnt[j]) {
valid = false;
break;
}
}
if (valid) {
ans = i;
break;
}
}
out.println(ans);
}
}
No comments:
Post a Comment