Page 9 of 30
Posted: Sat Nov 19, 2005 3:29 pm
by 10599
#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
>"<
Posted: Sat Nov 19, 2005 4:52 pm
by tan_Yui
Hi.
You have no need to write :
#ifndef ONLINE_JUDGE
close (0); open ("myprog.in", O_RDONLY);
close (1); open ("myprog.out1", O_WRONLY | O_CREAT, 0600);
#endif
Following is one of the example which is implemented.
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;
}
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.
10038 jolly jumpur
Posted: Sun Nov 27, 2005 3:31 pm
by liii
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;
}
Posted: Wed Nov 30, 2005 3:50 pm
by Tanu
I tried to check Ur code but it is not giving answer even for the sample input output... check it again...
Try...
Posted: Thu Dec 01, 2005 12:15 pm
by Roby
And here some input for you test (after you fix your program bug (posting above)):
And here's the correct output:
Hope it helps

progamming challenges website
Posted: Wed Jan 25, 2006 8:07 pm
by njc
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.
Posted: Thu Jan 26, 2006 8:33 am
by chunyi81
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.
Posted: Thu Jan 26, 2006 5:13 pm
by njc
thanks for the help. i wasn't aware that this judge had any of the same problems. and the compiler/ide i'm using automatically put the output on a new line for some reason, which is why i didn't understand how i was getting a WA.
Posted: Fri Feb 24, 2006 6:18 pm
by devious
two years later, and some one randomly decides to answer your question. You are only reading the first 255 characters on a line. There can be up to 2999 different numbers, all of which can be up to 4 characters long, and not to mention the spaces in between the numbers. 255? I don't think so lol
Posted: Fri Feb 24, 2006 8:08 pm
by Darko
Well, the thing is that he is using the "default" readLine() (as in official example of a Java submission).
I bet he figured out the pitfalls of such approach in the meantime
(It probably meant switching to C/C++)
Darko
10038 WHY CE
Posted: Mon Mar 13, 2006 6:20 pm
by chenyen
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;
}
Posted: Wed Mar 22, 2006 3:53 am
by fayyazkl
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
Posted: Wed Mar 22, 2006 4:14 am
by chunyi81
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.
Posted: Wed Mar 22, 2006 5:56 pm
by fpavetic
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.
Posted: Fri Mar 24, 2006 4:45 am
by chunyi81
int abs() is declared in stdlib.h or cstdlib.
My mistake
In newer versions of gcc it seems that cmath header included the int abs function as well.