Problem E: Jolly Jumpers A sequence of N> 0 integers is called a Jolly Jumper if the absolute values of the difference between successive elemtake 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 integerN<= 3000 followedNIntegers representing the sequence.
Outputfor each line of input, generate a line of output saying "Jolly" or "not jolly". sample input
4 1 4 2 35 1 4 2 -1 6
Sample output
JollyNot jolly
The absolute values of two adjacent numbers must be in [1, n), and each number in this range must appear once.
#include <stdio.h>#include <string.h>#include <stdlib.h>int vis[3002];int main(){int n, a, b, ok, t, m;while(scanf("%d", &n) != EOF){scanf("%d", &a);m = n; ok = 1;memset(vis, 0, sizeof(vis));while(--n){scanf("%d", &b);if(ok == 0) continue;if((t = abs(a - b)) == 0 || t >= m || vis[t])ok = 0; a = b; vis[t] = 1;}printf(ok ? "Jolly\n" : "Not jolly\n");}return 0;}