Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.InputStreamReader;
- import java.io.*;
- import java.util.*;
- public class JollyRancher {
- public static void main(String[] args) throws Exception {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- String line = br.readLine();
- while (line != null) {
- String[] input = line.split(" ");
- int[] input1 = new int[input.length-1];
- int n = Integer.parseInt(input[0]);
- for (int i = 1; i < input.length; i++) {
- input1[i-1] = Integer.parseInt(input[i]);
- }
- System.out.println(jollyRancher((input1), n));
- line = br.readLine();
- }
- }
- private static String jollyRancher(int[] input1, int n) {
- HashSet<Integer> nums = new HashSet<Integer>();
- for (int i = 1; i < n; i++) {
- nums.add(i);
- }
- for (int i = 0; i < input1.length; i++) {
- try {
- int val = Math.abs(input1[i - 1] - input1[i]);
- nums.remove(val);
- } catch (ArrayIndexOutOfBoundsException e) {
- }
- }
- if (nums.isEmpty()) {
- return "Jolly";
- } else {
- return "Not jolly";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement