Page 28 of 30

Re: 10038 - Jolly Jumpers

Posted: Thu Aug 21, 2014 12:30 pm
by RedCode119
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;
}

Re: 10038 - Jolly Jumpers

Posted: Thu Aug 21, 2014 7:35 pm
by brianfry713
Print "Not jolly" instead of "Not Jolly"

Re: 10038 - Jolly Jumpers

Posted: Fri Aug 22, 2014 12:01 am
by RedCode119
Thank u so much brainfry, i got it, it's a great mistake :P

Re:10038 - Jolly Jumpers

Posted: Wed Aug 27, 2014 7:47 am
by B_sayem
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;
}

Re: 10038 - Jolly Jumpers

Posted: Wed Aug 27, 2014 7:09 pm
by lighted
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

Re: 10038 - Jolly Jumpers

Posted: Wed Aug 27, 2014 7:40 pm
by brianfry713
Print a newline char at the end of each line.

10038- Jolly jumpers

Posted: Fri Sep 19, 2014 8:21 am
by imran_12
Got Ac

Re: 10038- Jolly jumpers

Posted: Fri Sep 19, 2014 11:06 am
by lighted
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)

Re: 10038- Jolly jumpers

Posted: Fri Sep 19, 2014 1:09 pm
by imran_12
Got Ac

Re: 10038- Jolly jumpers

Posted: Fri Sep 19, 2014 1:26 pm
by lighted
Input

Code: Select all

1 1
Acc Output

Code: Select all

Jolly

Re: 10038- Jolly jumpers

Posted: Fri Sep 19, 2014 1:39 pm
by imran_12
thank u lighted...finally i got AC....and um now deleting my code... :D

Re: 10038 - Jolly Jumpers

Posted: Tue Oct 07, 2014 6:36 am
by bgcsaif
i got WA. . . . Can you help me to correct it?
http://ideone.com/FJcIim

Re: 10038 - Jolly Jumpers

Posted: Tue Oct 07, 2014 10:12 am
by lighted
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

Re: 10038 - Jolly Jumpers

Posted: Tue Oct 07, 2014 1:09 pm
by bgcsaif
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. . . .

Re: 10038 - Jolly Jumpers

Posted: Tue Oct 07, 2014 1:18 pm
by lighted
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.