# Jolly Jumpers

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 This problem has been solved by kerry.
 This problem has been solved by mlc413.

 Sorter: kerry Unknown http://acm.pku.edu.cn/JudgeOnline/problem?id=2575

Jolly Jumpers is problem number 2575 on the Peking University ACM site.

```#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main() {
int i, num;
int input[3000];
while(1) {
for(i=0;i<3000;i++)
input[i]=0;
num=get_input(input);
if(num<=0) {
printf("Not jolly\n");
continue;
}
if (num==50000)
return;
}

}

int get_input(int input[3000]) {
int num, i;
if(scanf("%d", &num)==EOF)
return(50000);
if(num<=0)
while(getchar()!='\n'){}
for(i=0;i<num;i++)
scanf("%d", &input[i]);
return(num);

}

int compare(const void *a, const void *b) {
return(*(int*)a-*(int*)b);
}

int get_answer(int input[3000], int num){

if (num==1) {
printf("Jolly\n");
return;
}
for(i=0;i<3000;i++)
for(i=0;i<num-1;i++)

qsort(answer, num-1, sizeof(int), compare);
for(i=1;i<num;i++) {
printf("Not jolly\n");
return;
}
}
printf("Jolly\n");
return;
}

```

Melanie's Java Solution :

```

import java.util.*;

public class Main{

public static Scanner in;

public static void main(String[] args){
in=new Scanner(System.in);

doStuff();
}

public static void doStuff(){

while(in.hasNextInt()){
int N = in.nextInt();
solve(N);
}
}

public static void solve(int N){
int[] input = new int[N];
int[] diffs = new int[N-1];
for(int i = 0; i < N; i++){
input[i] = in.nextInt();
}

for(int i =0; i < N-1; i++){
diffs[i] = Math.abs( input[i]-input[i+1]);
}

boolean jolly = true;
Arrays.sort(diffs);
for(int i = 0; i < N -1; i++){
if(diffs[i]  != i+1)
jolly = false;
}

if(jolly){
System.out.println("Jolly");
}
else{
System.out.println("Not jolly");
}
}
}

```