Page 17 of 30

Re: 10038 - Jolly Jumpers

Posted: Thu Jul 01, 2010 10:41 am
by shaon_cse_cu08
jenovaforum wrote:This is the point where every 1 becomes fool....
Tnx for ur post i got AC without posting anything....


Sometime's other's mistakes can be ur Idea
:) :D

Re: 10038 - Jolly Jumpers

Posted: Sat Jul 03, 2010 8:20 am
by 6662666
can anybody help me to sort out the problem.I m getting runtime error again and again...:(

Code: Select all

#include<stdio.h>
#include<iostream.h>

int main()
{
long long i=0,temp1,temp2,dif,flag;
int n,check=1;
struct node
{
long long data;
node *next;
}*list,*tmp,*last;
list=NULL;
while(scanf("%d",&n)==1)
{
	flag=0;
	dif=1;
	check=1;
	if(n==1)
	{
		scanf("%lld",&temp2);
		printf("Not jolly\n");
		
	}
	else {

	for(i=0;i<n;i++)
	{

	  scanf("%lld",&temp2);
	  if(flag==1)
		continue;
	  if(i==0)
		temp1=temp2;
	  else dif=temp2-temp1;
	  temp1=temp2;

	  if(dif<0) dif=-dif;
	  if(dif>(n-1)) flag=1;
	  if(i>0&&list==NULL)
	  {

		if(dif<0)
		{
			list=new node;
			list->data=-dif;

		}
		else
		{
			list=new node;
			list->data=dif;
		}
		list->next=NULL;
	  }
	  else if(i>1)
	  {


		tmp=list;
		last=tmp;
		while(tmp->data<=dif&&tmp!=NULL)
		{
			last=tmp;
			tmp=tmp->next;
		}
		if(last->data==dif)
			flag=1;
		else
		{
			node *tmp1;
			tmp1=new node;
			if(last==list)
			{
				tmp1->data=dif;
				tmp1->next=list;
				list=tmp1;
			}
			else
			{

				tmp1->next=tmp;
				tmp1->data=dif;
				last->next=tmp1;
			}
		}//end of flag1 else

	  }//end of else
	}//end of for


	if(flag==1)
		printf("Not jolly\n");
	else
	{
		//printf("dif=%d\n",(tmp->data)-(last->data));
		last=list;
		tmp=list;
		while(tmp!=NULL)
		{

			if(tmp->data!=check)
			{
				printf("Not jolly\n");
				break;
			}

			tmp=tmp->next;
			check++;

		}//end of nested while

		if(tmp==NULL)
			printf("Jolly\n");
		else printf("Not jolly\n");



	}
	}//end of n=1 condition

}//end of while

exit(0);
return 0;
}

Re: 10038 - Jolly Jumpers

Posted: Sun Aug 08, 2010 3:13 am
by kawsar
Why i get WA, every time ??
can anyone explain about this problem.

#include<stdio.h>
#include<stdlib.h>

int main(){
long n, a[3000], b[3000], i, j ;

while(scanf("%ld",&n)==1){

for(i=0; i<n; i++)
scanf("%ld",&a);

if(n == 0 || n == 1){
printf("Jolly\n");
continue;
}

j=0;
for(i=1; i<n; i++)
b[j++] = abs(a - a[i-1]);

i=0;
if(b == 1){
i++;
while(i<j){
if(b[i-1]+1==b)
i++;
else
goto outer;
}
printf("Jolly\n");
continue;
}
else if(b == n-1){
i++;
while(i<j){
if(b[i-1]-1 == b)
i++;
else
goto outer;
}
printf("Jolly\n");
continue;
}
else{
printf("Not jolly\n") ;
continue;
}
outer:
printf("Not jolly\n") ;
}
return 0;
}


Plz, help me to find the error.

Re: 10038 - Jolly Jumpers

Posted: Sun Aug 08, 2010 4:09 am
by kawsar
I got accepted....just a few change of my code.
Thanks. :D

Re: 10038 - Jolly Jumpers

Posted: Sat Aug 14, 2010 6:46 am
by dewsworld
Could anyone please tell me why this is not working?????? :(

Code: Select all

Removed after AC

Re: 10038 - Jolly Jumpers

Posted: Sat Aug 14, 2010 3:19 pm
by helloneo
"Not Jolly" should be "Not jolly" :)

Re: 10038 - Jolly Jumpers

Posted: Fri Aug 27, 2010 1:17 pm
by dewsworld
"Not Jolly" should be "Not jolly"
That made me silly :D
Thanks Helloneo

Re: 10038 - Jolly Jumpers

Posted: Mon Sep 13, 2010 4:36 pm
by Deb20
Will you please explain me what is "Jolly jumper" & what is it's conditions.
Thank you.

Re: 10038 - Jolly Jumpers

Posted: Mon Sep 20, 2010 9:50 am
by tejas.deshpande
Hi I keep getting runtime error.
However when i test it with input from the forums it is giving correct answers

Code: Select all

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int inp;
bool list [3000];



int jumpers [3005];

string input;
int total_numbers;

void clear_first_number()
{
    int initial = 0;
    int final = 0;
    char buffer;
    for (int counter = 0; counter == counter ;++counter)
    {
        buffer = input[counter];
        if (buffer == ' ')
        {
            final = counter;
            ++ final;
            break;
        }
    }
    input.erase(0, final);
}

int subtract (int one, int two)
{
    int difference = one - two;
    if (difference < 0)
    {
        difference = -1*difference;
    }
    return difference;
}



int main()
{

    for (;;)// main loop till no input
    {
        int is_jolly = 1;
        input.clear();
        getline (cin, input);
        if (input.length() == 0)
        {
            return 0;
        }
        stringstream(input) >> total_numbers;
        clear_first_number();
        for (int i = 0 ; i < total_numbers; ++i)//process input string
        {
            stringstream(input) >> inp;
            jumpers[i] = inp;
            clear_first_number();

        }
        
        //create subtractions
        for (int j = 0; j < total_numbers ; ++j)
        {
            int difference = subtract(jumpers[j], jumpers[j+1]);
            jumpers[j] = difference;
        }
        

        //set bool array all to false
        for (int e = 0; e < total_numbers; ++e)
        {
            list [e] = false;
        }
        
        

        //make those indexes true which are present
        for (int t = 0; t < total_numbers ; ++t)
        {
            list[jumpers[t]-1] = true;
        }
        //check if jolly
        for (int d = 0; d < total_numbers-1; ++d)
        {
            if (list[d] == false)
            {
                is_jolly = 0;
            }
        }
        //print statements
        if (is_jolly == 1)
        {
            cout << "Jolly\n";
        }
        else
        {
            cout << "Not jolly\n";
        }

    }
}


Re: 10038 - Jolly Jumpers

Posted: Mon Mar 28, 2011 1:28 pm
by sbrown
Hi,

Could anyone tell me what is wrong with the code below, please? It works with the test input, but on the programming challenges website http://www.programming-challenges.com it is marked as being the wrong answer.

Code: Select all

#include <iostream>
#include <map>
#include <vector>
using namespace std;

int abs(int n);
map<int,int> sequence(int n);
void readInput();

int main()
{
    while(cin)
    {
        readInput();
    }

    return 0;
}

int abs(int n)
{
    int absoluteValue = n > 0 ? n : -n;
    return absoluteValue;
}

/* Takes a number n and returns a map with a sequence of
integers from n to n - 1 as the key, and a value of 0. */
map<int,int> sequence(int n)
{
    map<int,int> seq;
    while(n > 1){
       n--;
       seq.insert(make_pair(n,0));
    }
    return seq;
}

void readInput()
{
    bool jolly = true;
    vector<int> absolutes;
    int n;
    int next;
    int prev;
    int count = 0;
    cin>>n;

    map<int,int>seq = sequence(n);
    while(count < n)
    {
        if(count == 0)
        {
            prev = 0;
        }
        cin >> next;
        absolutes.push_back(abs(prev - next));
        prev = next;
        count++;
    }

    for(int i = 0;i < absolutes.size();i++){
       seq[absolutes[i]]++;
    }

    for(map<int,int>::const_iterator it = seq.begin();
        it != seq.end();it++){
       if(it->second == 0)
       {
           jolly = false;
       }
    }
    if(jolly || n == 1)
    {
        cout << "Jolly"<<endl;
    }
    else
    {
        cout << "Not jolly"<<endl;
    }
}




Re: 10038 - Jolly Jumpers

Posted: Sat Jul 02, 2011 10:37 am
by freshmen87
need help. don't know whats wrong with my code. its always WA

here is the code:
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;

string jolly(int count)
{
bool test[2998] = {0};
int temp, array[2999];
if(count > 0 && count < 3000)
{
for(int x =0;x < count;x++)
cin >> array[x];
if(count == 1)
return "Jolly\n";
for(int i=0;i < count-1;i++)
{
temp = abs(array - array[i+1]);
test[temp] = 1;
}

for(int x = 1;x < count; x++)
{
if(test[x] == 0)
return "Not jolly\n";
}
return "Jolly\n";
}
else
return "";
}

int main()
{
int input;
while(cin >> input)
{
cout << jolly(input);
}
return 0;
}



please help

Re: 10038 - Jolly Jumpers

Posted: Wed Aug 03, 2011 9:25 pm
by rupa_fn
my code is getting runtime error .. can some one tell me my problem plz
here is my code;

#include<iostream>
#include<stdlib.h>

using namespace std;

int main()
{
int n;
while(cin>>n)
{
int num[3001];
int num2[3001];
int num3[3001];
bool present[3000]={false};
int count=0;

for(int i=0; i<n; i++)
{
cin>>num;

}
int j=0;
for(int i=0; i<n; i++)
{

num2[j]=abs(num[i+1]-num);
present[num2[j]]=true;

j++;
}
int k=0;
for(int i=0; i<n-1; i++)
{
num3[k]=abs(num2[i+1]-num2);
k++;
}
for(int i=1; i<=n-1; i++)
{
if(present==false)
{
count++;
}
}
for(int i=0; i<n-2; i++)
{

if(num3!=1 )
{
count++;
}

}

if(count>0)
{
cout<<"Not Jolly\n";
}
else
{
cout<<"Jolly\n";
}
}

}

Re: 10038 - Jolly Jumpers

Posted: Wed Sep 07, 2011 7:51 am
by DigitalVoid
Heres my code and im wondering why im having WA. I tried those test cases on the board and it pass

Code: Select all

import java.util.Scanner;
import java.util.HashSet;

class Main 
{  
    public static void main(String []args)
    {
        Main jolly = new Main();
        jolly.jollyJumper();
    }
    
    void jollyJumper() 
    {
        java.util.Scanner console = new java.util.Scanner(System.in);
       
            int n = console.nextInt();
            int previous,ctr=1;
            HashSet set = new HashSet();
            
            if (n==1)
            {
                console.nextInt();
                System.out.println("Jolly");
            }
            else
            {
                previous = console.nextInt();
                while(n!=ctr)
                {
                    set.add(Math.abs(previous - (previous = console.nextInt())));
                    ctr++;
                }
                
                if(set.size()== n-1)
                {
                    if (isJolly(set,n-1))
                        System.out.println("Jolly");
                    else
                        System.out.println("Not jolly");
                }
                else
                    System.out.println("Not jolly");
                
            }
        
    }
    boolean isJolly(HashSet diff,int n)
    {
        for(int ctr = 1; ctr<=n;ctr++)
        {
            if(!diff.contains(ctr))
                return false;
        }
        return true;
    }
}


Re: 10038 - Jolly Jumpers

Posted: Fri Sep 09, 2011 11:34 am
by DigitalVoid
Please help me with the problem. I already run out of idea what possible mistake i had committed.

Re: 10038 - Jolly Jumpers

Posted: Sun Sep 18, 2011 6:52 pm
by wilsonsf
I didn't get AC yet, but i'm pretty sure the test isn't with the size of the set, but if the set contains numbers 1 through n-1.
E.g:
INPUT:
3 5 10 16
|5-10| = 5
|10-16| = 6
N is 3, N-1 = 2

Size would be 2, but the sequence would be 5,6 and "Not jolly"

--
Wilson de Farias

DigitalVoid wrote:Heres my code and im wondering why im having WA. I tried those test cases on the board and it pass

Code: Select all

import java.util.Scanner;
import java.util.HashSet;

class Main 
{  
    public static void main(String []args)
    {
        Main jolly = new Main();
        jolly.jollyJumper();
    }
    
    void jollyJumper() 
    {
        java.util.Scanner console = new java.util.Scanner(System.in);
       
            int n = console.nextInt();
            int previous,ctr=1;
            HashSet set = new HashSet();
            
            if (n==1)
            {
                console.nextInt();
                System.out.println("Jolly");
            }
            else
            {
                previous = console.nextInt();
                while(n!=ctr)
                {
                    set.add(Math.abs(previous - (previous = console.nextInt())));
                    ctr++;
                }
                
                if(set.size()== n-1)
                {
                    if (isJolly(set,n-1))
                        System.out.println("Jolly");
                    else
                        System.out.println("Not jolly");
                }
                else
                    System.out.println("Not jolly");
                
            }
        
    }
    boolean isJolly(HashSet diff,int n)
    {
        for(int ctr = 1; ctr<=n;ctr++)
        {
            if(!diff.contains(ctr))
                return false;
        }
        return true;
    }
}