You are on page 1of 1

/*

* Jolly Jumpers
* Programmer: Asir Mosaddek Sakib
* Language: C
* ID: 1109044
*/

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

int jolly[3005]; // this array is used to store the differences

int main()
{
int n, i, v, a, b;
int isJolly = 1; // Flag, 1 for Jolly, 2 for Not Jolly.
while(scanf("%d",&n)!=EOF){

isJolly = 1;

// initialize array with 0
memset(jolly, 0, sizeof(jolly));

scanf("%d", &a);

for(i=1; i<n; i++){
scanf("%d", &b);
v = abs(a-b); // Store the difference
/* If Difference = 0 or, Difference >= N
* or the difference already exist in the array
* then it is not a Jolly
*/
if(v==0 || v>=n || jolly[v])
isJolly = 0;
// Else we store the difference in the array.
else
jolly[v] = 1;
a = b;
}

if(isJolly)
printf("Jolly\n");
else
printf("Not jolly\n");
}
return 0;
}

You might also like