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

RedCode119
New poster
Posts: 13
Joined: Tue Jul 08, 2014 7:14 pm

Re: 10038 - Jolly Jumpers

Post by RedCode119 » Thu Aug 21, 2014 12:30 pm

This code is also getting Wrong Answer . I try all the test cases and it's showing everything correctly but still getting Wrong Answer.....

Code: Select all

#include <iostream>
#include<algorithm>
#include<stdlib.h>
using namespace std;
int main()
{
    int n,c,b[3001],a[3001],i,k;
    while(cin>>n)
    {
        c=1;
        for(i=0; i<n; i++)
        {
            cin>>a[i];
        }
        if(n==1)
            goto here;
        for(i=0; i<n-1; i++)
        {
            b[i]=abs(a[i+1]-a[i]);
        }
        sort(b,b+i);
        k=1;
        for(i=0; i<n-1; i++)
        {
            if(b[i]==k)
            {

            }
            else
            {
                c=0;
                break;
            }
             k++;

        }
        here:
        if(c==0)
           cout<<"Not Jolly"<<endl;
        else
            cout<<"Jolly"<<endl;
    }
    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 » Thu Aug 21, 2014 7:35 pm

Print "Not jolly" instead of "Not Jolly"
Check input and AC output for thousands of problems on uDebug!

RedCode119
New poster
Posts: 13
Joined: Tue Jul 08, 2014 7:14 pm

Re: 10038 - Jolly Jumpers

Post by RedCode119 » Fri Aug 22, 2014 12:01 am

Thank u so much brainfry, i got it, it's a great mistake :P

B_sayem
New poster
Posts: 7
Joined: Wed Dec 11, 2013 7:57 pm

Re:10038 - Jolly Jumpers

Post by B_sayem » Wed Aug 27, 2014 7:47 am

Why got Wrong Answer

Code: Select all

#include<iostream>
#include <stdlib.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    if(n==1)
    {
       cout<<"Jolly";
    }
    else{

    int dif1 = abs(a[0]-a[1]);
    int dif2 = abs(a[n-1]-a[n-2]);
    if (dif1==1)
    {
        for (int i=1;i<n-1;i++)
        {
            if(abs(a[i]-a[i+1])== (++dif1))
            {
                if(dif1 == n-1)
                {
                    cout<<"Jolly";
                }
            }
            else{
                cout<<"Not jolly";
                break;
            }
        }
    }
    else if(dif2==1)
    {
        for (int i= n-2;i>0;i--)
        {
            if(abs(a[i]-a[i-1])== (++dif2))
            {
                if(dif2 == n-1)
                {
                    cout<<"Jolly";
                }
            }
            else{
                cout<<"Not jolly";
                break;
            }
        }
    }
    else {
         cout<<"Not jolly";
    }

  }

    return 0;
}

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10038 - Jolly Jumpers

Post by lighted » Wed Aug 27, 2014 7:09 pm

You are printing answer only for the first case. You should print answer for each line.

Code: Select all

while (cin >> n) 
{
  int a[n];
  ..
}
Input

Code: Select all

4 1 2 5 7
Acc Output

Code: Select all

Jolly
Your output

Code: Select all

Not jolly
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

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

Re: 10038 - Jolly Jumpers

Post by brianfry713 » Wed Aug 27, 2014 7:40 pm

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

imran_12
New poster
Posts: 9
Joined: Fri Sep 19, 2014 7:56 am

10038- Jolly jumpers

Post by imran_12 » Fri Sep 19, 2014 8:21 am

Got Ac
Last edited by imran_12 on Fri Sep 19, 2014 1:40 pm, edited 1 time in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10038- Jolly jumpers

Post by lighted » Fri Sep 19, 2014 11:06 am

Post in existing threads. Don't open new thread. Use code tags.

http://acm.uva.es/board/viewtopic.php?f ... 04#p370951
See this thread and check your code for input posted there. One example. I reversed sample input
Input

Code: Select all

5 1 4 2 -1 6
4 1 4 2 3
Acc Output

Code: Select all

Not jolly
Jolly
Your Output

Code: Select all

Not jolly
Not jolly
Don't forget to remove your code after getting accepted. 8)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

imran_12
New poster
Posts: 9
Joined: Fri Sep 19, 2014 7:56 am

Re: 10038- Jolly jumpers

Post by imran_12 » Fri Sep 19, 2014 1:09 pm

Got Ac
Last edited by imran_12 on Fri Sep 19, 2014 1:42 pm, edited 1 time in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10038- Jolly jumpers

Post by lighted » Fri Sep 19, 2014 1:26 pm

Input

Code: Select all

1 1
Acc Output

Code: Select all

Jolly
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

imran_12
New poster
Posts: 9
Joined: Fri Sep 19, 2014 7:56 am

Re: 10038- Jolly jumpers

Post by imran_12 » Fri Sep 19, 2014 1:39 pm

thank u lighted...finally i got AC....and um now deleting my code... :D

bgcsaif
New poster
Posts: 38
Joined: Mon Sep 29, 2014 4:03 pm

Re: 10038 - Jolly Jumpers

Post by bgcsaif » Tue Oct 07, 2014 6:36 am

i got WA. . . . Can you help me to correct it?
http://ideone.com/FJcIim

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10038 - Jolly Jumpers

Post by lighted » Tue Oct 07, 2014 10:12 am

Try input in this thread before posting.
Input

Code: Select all

4 1 3 2 -2
3 4 1 3
Acc Output

Code: Select all

Not jolly
Not jolly
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

bgcsaif
New poster
Posts: 38
Joined: Mon Sep 29, 2014 4:03 pm

Re: 10038 - Jolly Jumpers

Post by bgcsaif » Tue Oct 07, 2014 1:09 pm

4
1 3 2 -2
Here, 1-3=2, 3-2=1, 2-(-2)=4
2,1,4=> 1,2,4
Ain't that jolly?
3
4 1 3
Here too, 4-1=3, 1-3=2
3,2=>2,3
Ain't that jolly too?
Please, brief me the task. May be i didn't understand it properly. . . .

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10038 - Jolly Jumpers

Post by lighted » Tue Oct 07, 2014 1:18 pm

A 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
Differences must be between [1..(n - 1)]. In input above differences are >= n, so answer is not jolly.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Post Reply

Return to “Volume 100 (10000-10099)”