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

thuongkhanh
New poster
Posts: 2
Joined: Tue Jul 12, 2011 5:28 pm

Re: 10038 - Jolly Jumpers

Post by thuongkhanh »

Hi all, I have question with this problem:

I used Dev C++ 4.9.9.2 to code. I had 2 code versions of this problem, and I have a problems with first version, it makes me Compile Error with abs function on Online Judge ( but Compile Succesful on Dev C)

This code make me COMPILE ERROR ( Dev C++ compile it succesfully )

Code: Select all

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    int n;
    int i;
    
    int jolly = 0;
    n = 0;
    int a[3001];
    int set[3001];
    int dif;
    cin>>n;
    while (n && n > 0)
    {
          
          for (i=0;i<n;i++)
          {
              cin>>a[i];
              set[i] = 0;
          }
              
          jolly = 1;
          for (i=1;i<n;i++)
            {
               dif = abs(a[i] - a[i-1]);
              
               if (dif != 0 && set[dif] == 0 && dif < n)
                  set[dif] = 1;
               else
               {
                   jolly = 0;
                   break;
               }
            }
         if (jolly ==1)
            cout<<"Jolly\n";
          else
              cout<<"Not jolly\n";        
         n = 0; 
         cin>>n;
    }
    return 0;
}
This is error message from Online Judge

Code: Select all

code.cpp: In function 'int main()':
code.cpp:27: error: 'abs' was not declared in this scope

And then I fixed it as below to get ACCEPTED

Code: Select all

#include <iostream>
using namespace std;
int main()
{
    int n;
    int i;
    
    int jolly = 0;
    n = 0;
    int a[3001];
    int set[3001];
    int dif;
    cin>>n;
    while (n && n > 0)
    {
          
          for (i=0;i<n;i++)
          {
              cin>>a[i];
              set[i] = 0;
          }
              
          jolly = 1;
          for (i=1;i<n;i++)
            {
               dif = a[i] - a[i-1];
               if (dif < 0)
                  dif = - dif;
               if (dif != 0 && set[dif] == 0 && dif < n)
                  set[dif] = 1;
               else
               {
                   jolly = 0;
                   break;
               }
            }
         if (jolly ==1)
            cout<<"Jolly\n";
          else
              cout<<"Not jolly\n";        
         n = 0; 
         cin>>n;
    }
    return 0;
}

Please explain for me

artless
New poster
Posts: 7
Joined: Tue Nov 22, 2011 2:01 pm

10038 why WA ??

Post by artless »

:evil: :evil: :roll: :roll: :( :(
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int n,num[3100],i,diff;
int flag;
while(cin>>n)
{
flag=1;
for(i=1;i<=n;i++)
scanf("%d",&num);
if(n!=1)
{
for(i=1;i<n;i++)
{
diff=fabs(num-num[i+1]);
if(diff>=n&&diff<1)
{
flag=0;
break;
}
}
}
if(flag==1)printf("Jolly\n");
else printf("Not jolly\n");
}

return 0;
}
:( :( :(

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 10038 why WA ??

Post by sohel »

Don't create a new thread for a problem that already exists. Make your post in an existing one.

Crocodile_009
New poster
Posts: 4
Joined: Thu Mar 08, 2012 8:11 am

Re: 10038 - Jolly Jumpers

Post by Crocodile_009 »

i got RE . where's my fault,plz anyone show me :(
my code is here:

#include<stdio.h>
#include<math.h>
int main()
{
int i,j,k,t,sub,temp,sum=0;
int ara[100];
while(scanf("%d",&t)==1){
j=(t*(t-1))/2;

for(i=0;i<t;i++) {
scanf("%d",&ara);
}
for(i=0;i<t-1;i++){
temp=abs(ara[i+1]-ara);
sum+=temp;
}
if(sum==j) printf("Jolly\n");
else
printf("Not jolly\n");
sum=0;
}
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 »

For abs(), include stdlib.h

Your ara array should be at least size 3000.
Check input and AC output for thousands of problems on uDebug!

kia.masster
New poster
Posts: 6
Joined: Thu Dec 22, 2011 8:47 am

Re: 10038 - Jolly Jumpers

Post by kia.masster »

Can Someone help me?
What's the problem of this code??? :-/

Code: Select all

#include <iostream>

using namespace std;

int main(){
	int n;
	while (cin >> n)
	{
		int m, j, d;
		cin >> m;
		bool jolly = true;
		bool inc1 = false;
		if (n > 1)
		{
			cin >> j;
			d = max(j, m) - min(j, m);
			if (d == n - 1)
				inc1 = false;
			else if (d == 1)
				inc1 = true;
			else
				jolly = false;
			m = j;
		}
		for (int i = 2; i < n; i++)
		{
			cin >> j;
			int de = max(j, m) - min(j, m);
			if (inc1)
				d++;
			else
				d--;
			if (de != d)
				jolly = false;
			m = j;
		}
		if (jolly)
			cout << "Jolly" << endl;
		else
			cout << "Not jolly" << endl;
	}
}

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

Re: 10038 - Jolly Jumpers

Post by brianfry713 »

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

3sam
New poster
Posts: 6
Joined: Mon Apr 09, 2012 8:33 pm

Re: 10038 - Jolly Jumpers

Post by 3sam »

i can`t get AC .....and don`t know why ????
this my code ::
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int arr[3000];
int n,result;
while(cin>>n)
{
for(int i=0;i<n;i++)
{
cin>>arr;
}
sort(arr,arr+n);
for(int i=2;i<=n;i++)
{
result=arr[n-1]-arr[n-i];
}
if(arr[n-1]-arr[0]==n-1||arr[n-1]-arr[0]==n||arr[n-1]-arr[0]==arr[n-1]-arr[n-2]+2)
{
cout<<"Jolly"<<endl;
}
else {
cout<<"Not 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 »

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

Sharkest
New poster
Posts: 5
Joined: Thu Apr 26, 2012 1:47 am

Re: 10038 - Jolly Jumpers

Post by Sharkest »

Can anyone tell me why my code is getting WA?
I have tested every single test case in this thread and the program generated the correct output.
Thanks in advance.

Code: Select all

Remove after AC.
Last edited by Sharkest on Sat Apr 28, 2012 1:03 am, edited 1 time in total.

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

Re: 10038 - Jolly Jumpers

Post by brianfry713 »

http://ideone.com/BdvZu

Doesn't match the sample I/O. There's an extra Not jolly at the end.
Check input and AC output for thousands of problems on uDebug!

Sharkest
New poster
Posts: 5
Joined: Thu Apr 26, 2012 1:47 am

Re: 10038 - Jolly Jumpers

Post by Sharkest »

That's odd, why does it give a different output here?
I compile the code then go to dos and do something like: jolly.exe <input.txt >output.txt
and the output is different from the one at the link.
What I'm doing wrong?
What should i do to provide input exactly as the judge do?Or I'm getting the output differently?
Thank you

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

Re: 10038 - Jolly Jumpers

Post by brianfry713 »

It's probably the way you are parsing input. Instead of peek, try doing:
while(scanf("%d", &n)==1) {
And you don't need to read input by the line, just read n integers.

Keep in mind the difference between DOS and UNIX newlines. Make sure there is a newline at the end of your input file.
Check input and AC output for thousands of problems on uDebug!

Sharkest
New poster
Posts: 5
Joined: Thu Apr 26, 2012 1:47 am

Re: 10038 - Jolly Jumpers

Post by Sharkest »

Thanks you!
Its working now, got AC.
Just out of curiosity, why there needs to be a newline at the end of input?its just a norm?

3sam
New poster
Posts: 6
Joined: Mon Apr 09, 2012 8:33 pm

Re: 10038 - Jolly Jumpers

Post by 3sam »

that`s my code and i do`t know why it`s WA always ...plz help me :) :) :)

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int x[3000],y,dif,flag,i;
int diff[3000];
while(cin>>y)
{
for(int i=0;i<y;i++)
{
cin>>x;
}
for(int i=0;i<y-1;i++)
{
dif=x-x[i+1];
if(dif<0)
{
dif=dif*-1;
}
diff=x-x[i+1];
if(diff<0)
{
diff=diff*-1;
}
}
if(dif>=1 && dif<y)
{
flag=1;
}
else
{
flag=5;
}
for(int i=0;i<y-1;i++)
{
if(diff==y)
{
flag=5;
}
if(diff==diff[i+1] ||diff==diff[i+2])
{
flag=5;
}
}
if(flag==5)
{
cout<<"Not jolly"<<endl;
}else
{
cout<<"Jolly"<<endl; }
}
return 0;
}

Post Reply

Return to “Volume 100 (10000-10099)”