10038 - Jolly Jumpers

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Thu Jun 27, 2013 11:56 pm

Change cin.ignore(256,'\n'); to something like cin.ignore(100000,'\n');
Check input and AC output for thousands of problems on uDebug!

raihan_sust5
New poster
Posts: 6
Joined: Tue Jul 23, 2013 3:04 am

Re: 10038 - Jolly Jumpers

Post by raihan_sust5 » Tue Jul 23, 2013 3:25 am

i am having wrong answer.....but i'm not understanding the problem....help me please :(

RoniphpBB
New poster
Posts: 10
Joined: Sat Feb 09, 2013 11:22 am

Re: 10038 - Jolly Jumpers

Post by RoniphpBB » Mon Aug 05, 2013 4:24 am

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;
    }



}



brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Tue Aug 06, 2013 2:08 am

Input 1 1 output should be Jolly
Check input and AC output for thousands of problems on uDebug!

walking_hell
New poster
Posts: 14
Joined: Tue Sep 24, 2013 4:35 pm

uva 10038

Post by walking_hell » Tue Oct 01, 2013 9:18 pm

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;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: uva 10038

Post by brianfry713 » Tue Oct 01, 2013 11:51 pm

4 1 4 3 5 is jolly
Check input and AC output for thousands of problems on uDebug!

The-PHx
New poster
Posts: 6
Joined: Sat Sep 28, 2013 10:32 pm

Re: 10038 - Jolly Jumpers

Post by The-PHx » Sat Oct 12, 2013 9:04 pm

Can you help me plz I'm getting WA here ?!?

Code: Select all

Got Accepted
:D
Last edited by The-PHx on Tue Oct 15, 2013 6:53 am, edited 1 time in total.

nitknight
New poster
Posts: 2
Joined: Mon Oct 14, 2013 8:29 pm

Re: 10038 - Jolly Jumpers

Post by nitknight » Mon Oct 14, 2013 8:31 pm

I am getting WA for below code.
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;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Mon Oct 14, 2013 8:40 pm

The-PHx, What if n = 3000?
nitknight, you're not clearing s
Check input and AC output for thousands of problems on uDebug!

nitknight
New poster
Posts: 2
Joined: Mon Oct 14, 2013 8:29 pm

Re: 10038 - Jolly Jumpers

Post by nitknight » Mon Oct 14, 2013 8:49 pm

brianfry713 wrote:The-PHx, What if n = 3000?
nitknight, you're not clearing s
Thanks brianfry713. It got accepted.

The-PHx
New poster
Posts: 6
Joined: Sat Sep 28, 2013 10:32 pm

Re: 10038 - Jolly Jumpers

Post by The-PHx » Tue Oct 15, 2013 6:54 am

brianfry713 wrote:The-PHx, What if n = 3000?
nitknight, you're not clearing s
thank you brianfry713 :D
got accepted

shakil.ruet.12
New poster
Posts: 1
Joined: Thu Aug 22, 2013 1:20 pm

Re: 10038 - Jolly Jumpers

Post by shakil.ruet.12 » Wed Oct 30, 2013 5:28 pm

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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Thu Oct 31, 2013 10:23 pm

2 1 1 is Not jolly
Check input and AC output for thousands of problems on uDebug!

d3nd0h
New poster
Posts: 8
Joined: Sun Nov 03, 2013 3:39 am

Re: 10038 - Jolly Jumpers

Post by d3nd0h » Fri Nov 08, 2013 7:43 am

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;
}
Guys, can u help me what's wrong with my code? I have been tried 15 times nothing changed still WA.

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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Fri Nov 08, 2013 10:36 pm

Always print a newline char at the end of the last line.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 100 (10000-10099)”