10038 - Jolly Jumpers
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10038 - Jolly Jumpers
Change cin.ignore(256,'\n'); to something like cin.ignore(100000,'\n');
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 6
- Joined: Tue Jul 23, 2013 3:04 am
Re: 10038 - Jolly Jumpers
i am having wrong answer.....but i'm not understanding the problem....help me please 

Re: 10038 - Jolly Jumpers
Why I am getting runtime plz help anyone........................
Code: Select all
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string.h>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
int main()
{
int T,n,i,opps=0;
vector<int>v;
vector<int>v1;
vector<int>v3;
while(cin>>T)
{
for(i=1;i<=T;i++)
{
cin>>n;
v.push_back(n);
}
for(int j=0;j<v.size()-1;j++)
{
int m=abs(v[j]-v[j+1]);
v1.push_back(m);
}
for(int k=0;k<v1.size()-1;k++)
{
int l=v1[k]-v1[k+1];
// if(v1[i]>v1[i+1])
{
if(l==1)
{
opps++;
}
v3.push_back(l);
}
}
if(opps==v3.size())
{
cout<<"Jolly"<<endl;
}
else cout<<"Not jolly"<<endl;
v.clear(),v1.clear(),v3.clear();opps=0;
}
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10038 - Jolly Jumpers
Input 1 1 output should be Jolly
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 14
- Joined: Tue Sep 24, 2013 4:35 pm
uva 10038
im getting wa again and again bt could not find my bug.pls help...
Code: Select all
#include<stdio.h>
#include<math.h>
int main()
{
int test,count,arr[3000],diff;
while(scanf("%d",&test)==1 && test>0 && test<=3000)
{
for(count=0;count<test;count++)
{
scanf("%d",&arr[count]);
}
for(count=0;count<test-1;count++)
{
if(count==0)
diff=abs(arr[count+1]-arr[count]);
else if(abs(arr[count+1]-arr[count])==diff-1)
diff=abs(arr[count+1]-arr[count]);
else
break;
}
if(count==test-1)
printf("Jolly\n");
else
printf("Not jolly\n");
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10038 - Jolly Jumpers
Can you help me plz I'm getting WA here ?!?

Code: Select all
Got Accepted

Last edited by The-PHx on Tue Oct 15, 2013 6:53 am, edited 1 time in total.
Re: 10038 - Jolly Jumpers
I am getting WA for below code.
Can somebody please help?
Can somebody please help?
Code: Select all
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main()
{
int n = 0;
set<int> s;
vector<bool> ansVec;
while(cin >> n)
{
int a = 0;
int b = 0;
if(n == 1)
{
cin >> a;
ansVec.push_back(true);
continue;
}
if(n == 0)
{
ansVec.push_back(false);
continue;
}
cin >> a;
bool bJollyJumper = true;
for(int i = 0; i < n-1; ++i)
{
cin >> b;
int diff = (b > a) ? b - a : a - b;
std::pair<set<int>::iterator, bool> bIns = s.insert(diff);
if(bIns.second == false)
{
bJollyJumper = false;
}
a = b;
}
if(bJollyJumper == true)
{
int i = 1;
set<int>::iterator it;
for(it = s.begin(); it != s.end(); ++it, ++i)
{
if(*it != i)
{
bJollyJumper = false;
break;
}
}
}
ansVec.push_back(bJollyJumper);
}
vector<bool>::iterator it;
for(it = ansVec.begin(); it != ansVec.end(); ++it)
{
if(*it == true)
{
cout << "Jolly\n";
}
else
{
cout << "Not jolly\n";
}
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10038 - Jolly Jumpers
The-PHx, What if n = 3000?
nitknight, you're not clearing s
nitknight, you're not clearing s
Check input and AC output for thousands of problems on uDebug!
Re: 10038 - Jolly Jumpers
Thanks brianfry713. It got accepted.brianfry713 wrote:The-PHx, What if n = 3000?
nitknight, you're not clearing s
Re: 10038 - Jolly Jumpers
thank you brianfry713brianfry713 wrote:The-PHx, What if n = 3000?
nitknight, you're not clearing s

got accepted
-
- New poster
- Posts: 1
- Joined: Thu Aug 22, 2013 1:20 pm
Re: 10038 - Jolly Jumpers
why i am getting WA ? plz correct me............
Code: Select all
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int n,a[3000],i,j,x,y,temp;
while(scanf("%d",&n)==1)
{
if(n<1)
{
printf("Jolly\n");
continue;
}
for(i=0;i<n;i++)
{
scanf("%d",&x);
if(i>0)
a[i-1]=(int)abs(x-y);
y=x;
}
sort(a,a+n-1);
temp=0;
if(a[0]==1||a[0]==0)
temp=1;
for(j=1;j<n-1;j++)
{
if((int)abs(a[j]-a[j-1])!=1)
{
temp=0;
break;
}
if(a[j]==1)
temp=1;
}
if(temp==1)
printf("Jolly\n");
else printf("Not jolly\n");
memset(a,'0',3000);
}
return 0;
}
[/b]
SHAKIL
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10038 - Jolly Jumpers
2 1 1 is Not jolly
Check input and AC output for thousands of problems on uDebug!
Re: 10038 - Jolly Jumpers
Code: Select all
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
using namespace std;
int main(){
int n;
vector<long> in;
bool first=1;
while(scanf("%d",&n)!=EOF){
bool jolly=1;
for(int i=0;i<n;i++){
int dum;
scanf("%d",&dum);
in.push_back(dum);
}
bool cek[n];
for(int i=1;i<n;i++){
int diff=abs(in[i]-in[i-1]);
if(diff>=n){
jolly=0;goto fin;
}
else cek[diff]=1;
}
for(int i=1;i<n;i++){
if(!cek[i]){
jolly=0;
break;
}
else{
jolly=1;
}
}
fin:
if(n==1)jolly=1;
if(!first)printf("\n");
if(jolly) printf("Jolly");
else printf("Not jolly");
first=0;
in.clear();
}
return 0;
}
Also I'm new to UVa can someone tell me how its handle the newline character. I mean when its safe to left the last line with \n and when it is not
Thx
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10038 - Jolly Jumpers
Always print a newline char at the end of the last line.
Check input and AC output for thousands of problems on uDebug!