Code: Select all
Get AC....
Moderator: Board moderators
Code: Select all
Get AC....
Code: Select all
2 1 2
4 1 4 3 1
4 1 4 2 3
5 1 4 2 -1 6
2 1 3
1 1
1 10
5 4 1 4 3 1
11 1 2 4 7 11 16 22 29 37 46 56
3 2 1 3
Code: Select all
Jolly
Jolly
Jolly
Not jolly
Not jolly
Jolly
Jolly
Not jolly
Jolly
Jolly
Code: Select all
thank you so much for the help :) Got AC
Change thisA 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.
Code: Select all
if(temp>1 && temp<=input-1){jolly[temp]=true;}
Code: Select all
if(temp>=1 && temp<=input-1){jolly[temp]=true;}
Change thisFor each line of input, generate a line of output saying "Jolly" or "Not jolly".
Code: Select all
else{cout << "Not Jolly" << endl;}
Code: Select all
else{cout << "Not jolly" << endl;}
Code: Select all
I got AC, thanks very much for the help
Code: Select all
if(scanf("%d",&n)==0);
break;
Code: Select all
if(scanf("%d",&n)==EOF)
break;
Code: Select all
while(scanf("%d",&n) == 1){
//clear vector and set
list.clear();
s.clear();
helloneo wrote:"Not Jolly" should be "Not jolly"
Code: Select all
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,a,b,sum;
while(cin>>n)
{
sum=((n*(n+1))/2)-n;
cin>>a;
b=a;
for(int i=0;i<n-1;i++)
{
cin>>a;
sum-=abs(a-b);
b=a;
}
if(sum==0) cout<<"Jolly"<<endl;
else cout<<"Not jolly"<<endl;
}
return 0;
}
Code: Select all
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int n,a,b,x,sub,old_sub,flag;
while(scanf("%d", &n)!=EOF)
{
cin>>a>>b;
n=n-2;
old_sub=a-b;
if(old_sub<0)
old_sub=old_sub*(-1);
a=b;
flag=1;
while(n)
{
cin>>x;
sub=a-x;
if(sub<0)
sub=sub*(-1);
a=x;
if(old_sub==sub || old_sub-sub==1)
{
}
else
{
flag=0;
}
old_sub=sub;
n--;
}
if(flag)
cout<<"Jolly"<<endl;
else
cout<<"Not Jolly"<<endl;
}
return 0;
}
Can't find out why it's showing time llimit exceeded. here's the code
Code: Select all
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main()
{
int n,a,b,x,sub,old_sub,flag;
while(cin>>n)
{
cin>>a>>b;
n=n-2;
old_sub=abs(a-b);
a=b;
flag=1;
while(n)
{
cin>>x;
sub=abs(a-x);
a=x;
if(old_sub==sub || old_sub-sub==1)
{
}
else
{
flag=0;
}
old_sub=sub;
n--;
}
if(flag)
cout<<"Jolly"<<endl;
else
cout<<"Not Jolly"<<endl;
}
return 0;
}
Code: Select all
while(n > 0)
Code: Select all
flag=1;
while(n > 0)
{
cin >> x;
Code: Select all
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main()
{
int n,a,b,x,sub,old_sub,flag,calc;
while(cin>>n)
{
if(n==0)
continue;
flag=1;
if(n==1)
{
cout<<"Jolly"<<endl;
continue;
}
cin>>a>>b;
old_sub=abs(a-b);
if(old_sub!=1 && old_sub!=n-1)
{
flag=0;
}
a=b;
n=n-2;
while(n)
{
cin>>b;
sub=abs(a-b);
calc=abs(old_sub-sub);
if(old_sub==sub || calc==1)
{
}
else
{
flag=0;
}
old_sub=sub;
a=b;
n--;
}
if(flag)
cout<<"Jolly"<<endl;
else
cout<<"Not Jolly"<<endl;
}
return 0;
}