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
#include"stdio.h"
#include"math.h"
int main()
{
 int a[30000],n,i,j,flag,k,temp,b[30000];
  while(scanf("%d",&n)!=EOF)//输入将要输入数组的个数;
  {
   j=0;
   flag=1;//给变量在循环中赋值;
   for(i=0;i<n;i++)
   {
    scanf("%d",&a[i]);
    if(i!=0)
    {b[j]=fabs(a[i]-a[j]);j++;}               
   }//求出每个相邻数的差值,然后保存在新数组;
   for(i=0;i<n-2;i++)
   for(j=1;j<n-1-i;j++)
  {if(b[j-1]>b[j])
   {temp=b[j-1];b[j-1]=b[j];b[j]=temp;}
  }//按从大到小冒牌排序;
   for(j=1;j<n-1;j++)
   {k=b[j]-b[j-1];
   if(k!=1)//看是不差值为1;
   flag=0;
   }
  if(flag)
  printf("Jolly\n");
  else printf("Not jolly\n"); 
  }  
  return 0; 
 }

 

posted on 2013-02-15 23:13  LOVE小熊ing  阅读(185)  评论(0编辑  收藏  举报