// CodeEval Jolly Jumpers
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
class Main {
public static void main(String[] args) {
jolly_jumpers.main(args);
}
}
class jolly_jumpers {
public static void main(String[] args) {
CodeEvalGetInput(args[0]);
// CodeEvalGetInput("e:\\zin.txt");
}
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) {
String[] lineArray = line.split("\\s");
if (lineArray.length > 0) {
// Process line of input Here
Process(lineArray);
}
}
} catch (IOException e) {
System.out.println("File Read Error: " + e.getMessage());
}
}
private static void Process(String[] lineArray) {
int N = Integer.valueOf(lineArray[0]);
Set<Integer> sets = new HashSet<Integer>();
boolean jolly = true;
for (int i = 1; i < N; i++) {
int diff = Integer.valueOf(lineArray[i + 1])
- Integer.valueOf(lineArray[i]);
diff = Math.abs(diff);
if (diff >= N || sets.contains(diff)) {
jolly = false;
break;
} else {
sets.add(diff);
}
}
System.out.println(jolly ? "Jolly" : "Not jolly");
}
}
No comments:
Post a Comment