can somebody write the c++ source code of this problem:
A sequence of n > 0 integers is called a jolly jumper if the absolute values of the differences between successive elements take on all possible values 1 through n - 1. For instance,
1 4 2 3
is a jolly jumper, because the absolute differences are 3, 2, and 1, respectively. The definition implies that any sequence of a single integer is a jolly jumper. Write a program to determine whether each of a number of sequences is a jolly jumper.
Input
Each line of input contains an integer n < 3, 000 followed by n integers representing the sequence.
Output
For each line of input generate a line of output saying ``Jolly'' or ``Not jolly''.
Just because you phrase it as a "challenge" doesn't mean we'll do your homework for you. At least try to do the work yourself, post your code, and you will get some help...
BTW, "Jolly Jumper"??? I thought that was a spring loaded chair for toddlers.
Hey Guys, my source code is:
#include <iostream>
using namespace std;
int absl(int a, int b)
{
if(a>b) return a-b;
if(a<b) return -1*(a-b);
if(a==b) return 0;
}
void read_row()
{
int n;
cin>>n;
int seq[n];
int seq2[n-1];
for(int i=1; i<n;i++) seq2[i]=i;
int j=0;
int m;
while(j<n){
cin>>m;
seq[j]=m;
j++;
}
for(int i=0; i<n-1; i++){
for(int j=1; j<n; j++)
{
if(absl(seq[i],seq[i+1])==seq2[j]){
seq2[j]=0;
break;
}
}
}
int count =0;
for(int i=1; i<n; i++) if(seq2[i]!=0){
count+=1;
break;
}
if(count==0) cout<<"jolly"<<endl;
else cout<<"Not jolly"<<endl;
}
int main()
{
while(cin)
read_row();
return 0;
}
Please, just correct if i have mistake, but I want from you how to deal with the problem's input/output
Input
Each line of input contains an integer n < 3, 000 followed by n integers representing the sequence.
Output
For each line of input generate a line of output saying ``Jolly'' or ``Not jolly''.
What you mean? I just want to learn porgramming! And if somebody has ever joined or submitted problems solutions to programming-challenges.com and got correct answer, please help me