10038 - Jolly Jumpers
Moderator: Board moderators
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
int main()
{long int n,a[3000],b[3000],c[3000],d[3000],e,i,k,t,x;
#ifndef ONLINE_JUDGE
close (0); open ("myprog.in", O_RDONLY);
close (1); open ("myprog.out1", O_WRONLY | O_CREAT, 0600);
#endif
while( scanf("%ld",&n)==1){
for(i=0;i<n;i++)
{scanf("%ld",&a);}
for(k=0,t=1;k<(n-1);k++,t++)
{b[k]=t;d[k]=0;}
for(i=0;i<(n-1);i++)
{c=a[i+1]-a;
if(c<0)
c=-c;
for(k=0;k<(n-1);k++)
{for(e=0;e<(n-1);e++)
{if(c[k]==b[e])
d[e]++;}
}
}
for(k=0;k<(n-1);k++)
{if(d[k]==0)
{printf("Not jolly\n");
x=0;
goto end;}
else
x=1;
}
end:
if(x==1&&d[n-1]==0)
printf("Jolly\n");
}
return 0;
}
while( scanf("%ld",&n)==1)
OR
while( scanf("%ld",&n)!=EOF)
TLE
>"<
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
int main()
{long int n,a[3000],b[3000],c[3000],d[3000],e,i,k,t,x;
#ifndef ONLINE_JUDGE
close (0); open ("myprog.in", O_RDONLY);
close (1); open ("myprog.out1", O_WRONLY | O_CREAT, 0600);
#endif
while( scanf("%ld",&n)==1){
for(i=0;i<n;i++)
{scanf("%ld",&a);}
for(k=0,t=1;k<(n-1);k++,t++)
{b[k]=t;d[k]=0;}
for(i=0;i<(n-1);i++)
{c=a[i+1]-a;
if(c<0)
c=-c;
for(k=0;k<(n-1);k++)
{for(e=0;e<(n-1);e++)
{if(c[k]==b[e])
d[e]++;}
}
}
for(k=0;k<(n-1);k++)
{if(d[k]==0)
{printf("Not jolly\n");
x=0;
goto end;}
else
x=1;
}
end:
if(x==1&&d[n-1]==0)
printf("Jolly\n");
}
return 0;
}
while( scanf("%ld",&n)==1)
OR
while( scanf("%ld",&n)!=EOF)
TLE
>"<
Hi.
You have no need to write :
This code tries to read the lines till EOF.
(Of course, the original code is yours. I changed some parts. )
By the way, you'll failed for some inputs.
-> http://online-judge.uva.es/board/viewto ... ight=10038
And, there have already been many threads in this board.
You can search by using the word "10038".
This will help you for your coding.
Best regards.
You have no need to write :
Following is one of the example which is implemented.#ifndef ONLINE_JUDGE
close (0); open ("myprog.in", O_RDONLY);
close (1); open ("myprog.out1", O_WRONLY | O_CREAT, 0600);
#endif
This code tries to read the lines till EOF.
(Of course, the original code is yours. I changed some parts. )
Code: Select all
#include <stdio.h>
int main() {
long int n,a[3000],b[3000],c[3000],d[3000],e,i,k,t,x;
while(scanf("%ld",&n)!=EOF) {
for(i=0;i<n;i++) {scanf("%ld",&a[i]);}
for(k=0,t=1;k<(n-1);k++,t++) {
b[k]=t;d[k]=0;
}
for(i=0;i<(n-1);i++) {
c[i]=a[i+1]-a[i];
if(c[i]<0) c[i]=-c[i];
for(k=0;k<(n-1);k++) {
for(e=0;e<(n-1);e++) {
if(c[k]==b[e]) d[e]++;
}
}
}
for(k=0;k<(n-1);k++) {
if(d[k]==0) {
printf("Not jolly\n");
x=0;
goto end;
}
else
x=1;
}
end:
if(x==1&&d[n-1]==0) printf("Jolly\n");
}
return 0;
}
-> http://online-judge.uva.es/board/viewto ... ight=10038
And, there have already been many threads in this board.
You can search by using the word "10038".
This will help you for your coding.
Best regards.
10038 jolly jumpur
I am getting wrong answer.Where is problem? plz help me.
Code: Select all
#include<stdio.h>
#include<iostream.h>
//#include<algorithum.h>
int main()
{ long int n,a[4000],s=0,jo=1,p=0;
while(cin>>n)
{
//if(n==0)
//break;
for(long int i=0;i<n;i++)
{
cin>>a[i];
}
//cout<<a[5];
for(long int j=1;j<n;j++)
{ //p=0;
if(a[j-1]<a[j])
{ s=0;
for(int t=a[j-1];t<a[j];t++)
{s++;}
if(s<4)
jo*=1;
else
jo*=0;
//p=1;
//jo*=p;
}
if(a[j-1]>a[j])
{ s=0;
for(int y=a[j];y<a[j-1];y++)
{s++;}
if(s<4)
jo*=1;
else
jo*=0;
//p=1;
}
}
if(jo==1 && p==1)
cout<<"Jolly"<<endl;
if(jo==0)
cout<<"Not jolly"<<endl;
}
return 0;
}
-
- Experienced poster
- Posts: 101
- Joined: Wed May 04, 2005 4:33 pm
- Location: Tangerang, Banten, Indonesia
- Contact:
And here some input for you test (after you fix your program bug (posting above)):
And here's the correct output:
Hope it helps 
Code: Select all
4 1 4 2 3
5 1 4 2 -1 6
4 1 4 3 5
Code: Select all
Jolly
Not jolly
Jolly

progamming challenges website
i've been trying the website for the progamming challenges book (on the front page of the online-judge site)
i'm having trouble submitting my code. it seems to work properly and give correct output, but everything i try submitting i get a wrong answer reply.
for example:
this problem: http://www.programming-challenges.com/p ... ormat=html
here is my code:
it seems to work, but i get a wrong answer when submitting. this isn't the only one either.
does that site use this online judge or a different one? any help would be great. thanks.
i'm having trouble submitting my code. it seems to work properly and give correct output, but everything i try submitting i get a wrong answer reply.
for example:
this problem: http://www.programming-challenges.com/p ... ormat=html
here is my code:
Code: Select all
*fixed*
does that site use this online judge or a different one? any help would be great. thanks.
Last edited by njc on Thu Jan 26, 2006 5:13 pm, edited 1 time in total.
Please check your code carefully before posting. Obviously there is something wrong with your code. Which is why the judge at programming challenges website says WA. By the way, I believe the problem you are referrig to in your code is problem 10038 Jolly Jumpers of this judge. You could have tried searching for threads related to problems 10038 here.
Also, try this input:
Your code prints
You forgot to print a newline ('\n') after each line of output. Now remove this code after you get AC.
Also, try this input:
Code: Select all
1 1
4 1 4 2 3
Code: Select all
JollyJolly
10038 WHY CE
it can run on my computer but ...online-judge give me Complie ERROR

Code: Select all
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n=0,i=0,j[3000]={0};
bool isj=true;
while(1)
{
cin >> n;
if(cin.fail()) break;
for(i=0;i<n;i++)
{
cin >> j[i];
}
isj=true;
for(i=0;i<(n-1);i++)
{
if((abs((j[i+1]-j[i]))<1)||(abs((j[i+1]-j[i]))>(n-1)))
{
isj=false;
cout << "Not jolly" << endl;
break;
}
}
if(isj==true)
cout << "Jolly" << endl;
}
return 0;
}
I dont think bool data type is part of C++ ANSI standard. You might be using Visual Studio or something which works but this wont
There are 10 types of people. Those who can read binary and those who cant 
http://acm.uva.es/problemset/usersjudge.php?user=37504

http://acm.uva.es/problemset/usersjudge.php?user=37504
bool will compile in this online judge.
However, the compile error lies in the use of the abs function. I suggest you explicitly cast the expression you pass to the abs function to a double, and then you cast the value returned from abs back to int. Alternatively, as a workaround, #include math.h instead of cmath.
However, the compile error lies in the use of the abs function. I suggest you explicitly cast the expression you pass to the abs function to a double, and then you cast the value returned from abs back to int. Alternatively, as a workaround, #include math.h instead of cmath.
int abs() is declared in stdlib.h or cstdlib.However, the compile error lies in the use of the abs function. I suggest you explicitly cast the expression you pass to the abs function to a double, and then you cast the value returned from abs back to int. Alternatively, as a workaround, #include math.h instead of cmath.