Skip to main content

UVa 10038 - Jolly Jumpers Solution

UVa 10038 - Jolly Jumpers


Description: 


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’.

Solution:

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

int main()
{
    int n,arr[4000],item[4000],i,j,diff=0;
    while(scanf("%d",&n)==1)
    {
        for(i=1;i<=n;i++)
            arr[i]=0;
        for(i=1;i<=n;i++)
            scanf("%d",&item[i]);
        if(n!=1)
        {
            for(i=1;i<n;i++)
            {
                diff=abs(item[i]-item[i+1]);
                if(arr[diff]==0)
                    arr[diff]=1;
                else
                {
                    printf("Not jolly\n");
                    break;
                }
                if(i==(n-1))
                {
                    for(j=1;j<n;j++)
                    {
                        if(arr[j]==0)
                        {
                            printf("Not jolly\n");
                            break;
                        }
                        else if(j==(n-1))
                            printf("Jolly\n");
                    }
                }
            }
        }
        else
            printf("Jolly\n");
    }

    return 0;
}



See More Solution:

Comments

Populer Article

UVa 10082 - WERTYU Solution

UVa  10082 - WERTYU Description:   A common typing error is to place the  hands on the keyboard one row to the  right of the correct position. So ‘Q’ is  typed as ‘W’ and ‘J’ is typed as ‘K’ and  so on. You are to decode a message typed in this manner. Input Input consists of several lines of text. Each line may contain digits, spaces, upper case letters (except  Q, A, Z), or punctuation shown above [except back-quote (‘)]. Keys labelled with words [Tab, BackSp,  Control, etc.] are not represented in the input. Output You are to replace each letter or punction symbol by the one immediately to its left on the ‘QWERTY’  keyboard shown above. Spaces in the input should be echoed in the output. Sample Input O S, GOMR YPFSU/ Sample Output I AM FINE TODAY.  Solution #include<stdio.h> int main () { char str[10000], key[]={'`','1','2','3','4','5','6','7','8','9','0', '-','=','...

UVa 10062 - Tell me the frequency Solution

UVa  10062 - Tell me the frequency Description:  Given a line of text you will have to find out the frequencies of the ASCII characters present in it. The  given lines will contain none of the first 32 or last 128 ASCII characters. Of course lines may end with  \n and \r but always keep those out of consideration. Input Several lines of text are given as input. Each line of text is considered as a single input. Maximum  length of each line is 1000. Output Print the ASCII value of the ASCII characters which are present and their frequency according to the  given format below. A blank line should separate each set of output. Print the ASCII characters in the  ascending order of their frequencies. If two characters are present the same time print the information  of the ASCII character with higher ASCII value first. Input is terminated by end of file. Sample Input AAABBC 122333 Sample Output 67 1 66 2 65 3 49 1 50 2 51 3 Solution #include<stdio.h...

UVa 10079 - Pizza Cutting Solution

UVa 10079 - Pizza Cutting Description:  When someone calls Ivan lazy, he claims that it is his intelligence that helps him to be so. If his intelligence allows him to do something at less physical effort, why should he exert more? He also claims that he always uses his brain and tries to do some work at less effort; this is not his laziness, rather this is his intellectual smartness. Once Ivan was asked to cut a pizza into seven pieces to distribute it among his friends. (Size of the pieces may not be the same. In fact, his piece will be larger than the others.) He thought a bit, and came to the conclusion that he can cut it into seven pieces by only three straight cuts through the pizza with a pizza knife. Accordingly, he cut the pizza in the following way (guess which one is Ivan’s piece): One of his friends, who never believed in Ivan’s smartness, was startled at this intelligence. He thought, if Ivan can do it, why can’t my computer? So he tried to do a similar (but not ex...