Skip to content

Instantly share code, notes, and snippets.

@alvineadel
Last active December 30, 2015 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvineadel/7810163 to your computer and use it in GitHub Desktop.
Save alvineadel/7810163 to your computer and use it in GitHub Desktop.
UVA - 10038 - Jolly Jumpers

Problem E: Jolly Jumpers

A sequence of n > 0 integers is called a jolly jumper if the absolute values of the difference between successive elements take on all the values 1 through n-1. For instance,

1 4 2 3
is a jolly jumper, because the absolutes differences are 3, 2, and 1 respectively. The definition implies that any sequence of a single integer is a jolly jumper. You are to write a program to determine whether or not each of a number of sequences is a jolly jumper.

Input

Each line of input contains an integer n <= 3000 followed by n integers representing the sequence.

Output

For each line of input, generate a line of output saying "Jolly" or "Not jolly".

Sample Input

4 1 4 2 3
5 1 4 2 -1 6

Sample Output

Jolly
Not jolly
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner in = new Scanner(System.in);
while(in.hasNext()){
int N = in.nextInt(), sum = N*(N-1)/2;
if(N>0){
int n = in.nextInt();
for(int d, i=1; i<N; i++, sum-=d){
d = Math.abs(n-(n=in.nextInt()));
d = d==0? -1<<20 : d;
}
}
System.out.println(sum==0 ? "Jolly" : "Not jolly");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment