0% found this document useful (0 votes)
1K views1 page

Jolly Jumpers Solution Java

Solution for "Jolly Jumpers" from the book "Programming Challenges" by Steven Skiena. Implemented in Java.

Uploaded by

frmlssty
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views1 page

Jolly Jumpers Solution Java

Solution for "Jolly Jumpers" from the book "Programming Challenges" by Steven Skiena. Implemented in Java.

Uploaded by

frmlssty
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

//Jolly Jumpers Solution import java.util.HashMap; import java.util.Map; import java.util.

Scanner; public class JollyJumpers { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(in.hasNextLine()){ Scanner line = new Scanner(in.nextLine()); int numNums = line.nextInt(); int[] numbers = new int[numNums]; Map<Integer, Boolean> seenIt = new HashMap<Integer, Boolean>(); for(int n = 1; n <= numNums; n++){ numbers[n - 1] = line.nextInt(); seenIt.put((n), false); } seenIt.remove((numNums)); for (int n = 1; n < numNums; n++){ int diff = Math.abs(numbers[n - 1] numbers[n]); seenIt.put(diff, true); } boolean flag = false; for(int n = 1; n < numNums; n++){ if(seenIt.get(n) == false){ System.out.println("Not Jolly"); flag = true; break; } } if(flag == false){ System.out.println("Jolly"); } System.out.println(seenIt.toString()); } } }

You might also like