Jolly Jumper
Jolly Jumper
A sequence ofn>0 integers is called ajolly jumper if the absolute values of the
differences between successive elements take on all possible values 1 throughn1. For
instance,
1423
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.
*/
/*
SAIF KHAWAJA BC113010
MOHSIN ALTAF BC103102
*/
#include<iostream>
using namespace std;
void main()
{
int value,f1,f2,f3;
char y;
do{
cout<<"Enter the value to check jolly jumper"<<endl;
cin>>value;
if(value>=1000)
{
cout<<"Value greater than 1000 type again"<<endl;
}//1
else if(value>99)
{
f1 = value/100;
f2 = value%100;
f3 = f2/10;
f2 = f2 % 10;
if(f3<=f1&&f3>=f2)
{
if(f1-f3<=f3-f2)
{
if((f1-f3)+1==f3-f2||(f1-f3)==f3-f2)
cout<<"Jolly Jumper"<<endl;
else
cout<<"NOT JOLLY JUMPER"<<endl;
}
else if(f1-f3>=f3-f2)
{
if((f1-f3)-1==f3-f2||(f1-f3)==f3-f2)
cout<<"Jolly Jumper"<<endl;
else
cout<<"NOT JOLLY JUMPER"<<endl;
}
}//condition 1
else if(f3>=f1&&f3<=f2)
{
if(f3-f1<=f2-f3)
{
if((f3-f1)+1==f2-f3||(f3-f1)==f2-f3)
cout<<"Jolly Jumper"<<endl;
else
cout<<"NOT JOLLY JUMPER"<<endl;
}
else if(f3-f1>=f2-f3)
{
if((f3-f1)-1==f2-f3||(f3-f1)==f2-f3)
cout<<"Jolly Jumper"<<endl;
else
cout<<"NOT JOLLY JUMPER"<<endl;
}
}//conditon 2
else if(f3>=f1&&f3>=f2)
{
if(f3-f1<=f3-f2)
{
if((f3-f1)+1==f3-f2||(f3-f1)==f3-f2)
cout<<"Jolly Jumper"<<endl;
else
cout<<"NOT JOLLY JUMPER"<<endl;
}
else if(f3-f1>=f3-f2)
{
if((f3-f1)-1==f3-f2||(f3-f1)==f3-f2)
cout<<"Jolly Jumper"<<endl;
else
cout<<"NOT JOLLY JUMPER"<<endl;
}
}//condtion 3
else if(f3<=f1&&f2>=f3)
{
if(f1-f3<=f2-f3)
{
if((f1-f3)+1==f2-f3||(f1-f3)==f2-f3)
cout<<"Jolly Jumper"<<endl;
else
cout<<"NOT JOLLY JUMPER"<<endl;
}
else if(f1-f3>=f2-f3)
{
if((f1-f3)-1==f2-f3||(f1-f3)==f2-f3)
cout<<"Jolly Jumper"<<endl;
else
cout<<"NOT JOLLY JUMPER"<<endl;
}
}//condition 4
}//2
else if(value<99)
{
cout<<"NOT JOLLY JUMPER"<<endl;
}
cout<<"WANT TO ENTER VALUE AGAIN ENTER Y"<<endl;
cin>>y;
}while(y=='y');//3
}//END