10038  Jolly Jumpers
Moderator: Board moderators
Hi Hiro,
your code seems to be in perfect condition but the breaking condition of the while loop seems to be a little disarrayed.
.. I slightly modified that part and your code got AC.
Change
[c]
while ((c = getchar()) != '\n')
{
cin.putback(c);
int n;
cin >> n;
[/c]
to
[c]
int n;
while (cin>>n)
{
// ........
}
[/c]
and it should get AC.
your code seems to be in perfect condition but the breaking condition of the while loop seems to be a little disarrayed.
.. I slightly modified that part and your code got AC.
Change
[c]
while ((c = getchar()) != '\n')
{
cin.putback(c);
int n;
cin >> n;
[/c]
to
[c]
int n;
while (cin>>n)
{
// ........
}
[/c]
and it should get AC.
Hi Sohel!!!
I modified my code as you suggested and i got AC.
Thank you a lot.... i couldn't see what was wrong with my code.....
But i still don't understand why the code:
while ((c = getchar()) != '\n')
{
cin.putback(c);
int n;
cin >> n;
....
}
don't get accepted?
I tested your suggestion in my computer and when a press only enter, the program doesn't finish. But when i redirect my standard input to a file, it works perfectly. Why does this happens? I am using cygnus g++ under windows Xp.
The input of the problem requires that you press enter if you finish the test cases isnt it? I am having big problems with my input!!
If you could help me!!
Thanks!!
I modified my code as you suggested and i got AC.
Thank you a lot.... i couldn't see what was wrong with my code.....
But i still don't understand why the code:
while ((c = getchar()) != '\n')
{
cin.putback(c);
int n;
cin >> n;
....
}
don't get accepted?
I tested your suggestion in my computer and when a press only enter, the program doesn't finish. But when i redirect my standard input to a file, it works perfectly. Why does this happens? I am using cygnus g++ under windows Xp.
The input of the problem requires that you press enter if you finish the test cases isnt it? I am having big problems with my input!!
If you could help me!!
Thanks!!

 New poster
 Posts: 8
 Joined: Tue Oct 12, 2004 1:54 pm
 Location: IranTehran
 Contact:
10038 Why RTE (Runtime Error)
This is my solution for problem 10038 {Jolly Jumpers}
but I don't know why RTE
Please help me !
Thanks
[cpp]
//http://acm.uva.es/p/v100/10038.html
#include<stdio.h>
int main()
{
long long int Jolly[3000];
long long int Sequence[3001];
long long int n,i,j,minus;
while(scanf("%lld",&n)==1)
{
for(i=1;i<=n;i++)
{
scanf("%lld",&Sequence);
Jolly=1;
}
long long int r=1;
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
{
minus=SequenceSequence[j];
if(minus<0)minus*=1;
if(minus>=1&&minus<=(n1))
Jolly[minus]=0;
else
{r=0;break;}
}
for(i=1;i<=(n1);i++)
if(Jolly==1)
{r=0;break;}
if(r)
printf("Jolly\n");
else
printf("Not jolly\n");
}
return 0;
}
[/cpp]
but I don't know why RTE
Please help me !
Thanks
[cpp]
//http://acm.uva.es/p/v100/10038.html
#include<stdio.h>
int main()
{
long long int Jolly[3000];
long long int Sequence[3001];
long long int n,i,j,minus;
while(scanf("%lld",&n)==1)
{
for(i=1;i<=n;i++)
{
scanf("%lld",&Sequence);
Jolly=1;
}
long long int r=1;
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
{
minus=SequenceSequence[j];
if(minus<0)minus*=1;
if(minus>=1&&minus<=(n1))
Jolly[minus]=0;
else
{r=0;break;}
}
for(i=1;i<=(n1);i++)
if(Jolly==1)
{r=0;break;}
if(r)
printf("Jolly\n");
else
printf("Not jolly\n");
}
return 0;
}
[/cpp]
Hi habibiamin,
A part of your code:
[c]
long long int Jolly[3000];
long long int Sequence[3001];
long long int n,i,j,minus;
while(scanf("%lld",&n)==1)
{
for(i=1;i<=n;i++)
{
scanf("%lld",&Sequence);
Jolly=1;
}
[/c]
If n=3000 then you are assigning Jolly[3000] as 1 but your Jolly array can handle from 0 to 2999 and hence the cause of RTE..
.. You can get rid of RTE by enlarging the array size but I must warn that we will get WA.
and try to avoid long long when it's not needed.
A part of your code:
[c]
long long int Jolly[3000];
long long int Sequence[3001];
long long int n,i,j,minus;
while(scanf("%lld",&n)==1)
{
for(i=1;i<=n;i++)
{
scanf("%lld",&Sequence);
Jolly=1;
}
[/c]
If n=3000 then you are assigning Jolly[3000] as 1 but your Jolly array can handle from 0 to 2999 and hence the cause of RTE..
.. You can get rid of RTE by enlarging the array size but I must warn that we will get WA.
and try to avoid long long when it's not needed.

 New poster
 Posts: 8
 Joined: Tue Oct 12, 2004 1:54 pm
 Location: IranTehran
 Contact:

 New poster
 Posts: 4
 Joined: Sat Nov 13, 2004 12:17 pm
 Location: Dhaka,Bangladesh
 Contact:
10038
I dont understand why do I get WA . Can any one check this code plz:
[c]
#include<stdio.h>
#include<stdlib.h>
void main(){
long int n,i,f1,f2,diff,bool,array[3005]={0};
FILE *infile,*outfile;
infile=stdin;
outfile=stdout;
while(1){
if(feof(infile)) break;
fscanf(infile,"%ld",&n);
fscanf(infile,"%ld",&f1);
for(i=0;i<n;i++)
array=0;
for(i=1;i<n;i++){
fscanf(infile,"%ld",&f2);
diff=abs(f1f2);
if (diff<n && diff>0)
array[diff]=1;
f1=f2;
}
bool=1;
for(i=1;i<n;i++){
if(array==0){
bool=0;
}
}
if (bool==0)
fprintf(outfile,"Not Jolly\n");
else
fprintf(outfile,"Jolly\n");
}
}[/c]
[c]
#include<stdio.h>
#include<stdlib.h>
void main(){
long int n,i,f1,f2,diff,bool,array[3005]={0};
FILE *infile,*outfile;
infile=stdin;
outfile=stdout;
while(1){
if(feof(infile)) break;
fscanf(infile,"%ld",&n);
fscanf(infile,"%ld",&f1);
for(i=0;i<n;i++)
array=0;
for(i=1;i<n;i++){
fscanf(infile,"%ld",&f2);
diff=abs(f1f2);
if (diff<n && diff>0)
array[diff]=1;
f1=f2;
}
bool=1;
for(i=1;i<n;i++){
if(array==0){
bool=0;
}
}
if (bool==0)
fprintf(outfile,"Not Jolly\n");
else
fprintf(outfile,"Jolly\n");
}
}[/c]

 New poster
 Posts: 4
 Joined: Sat Nov 13, 2004 12:17 pm
 Location: Dhaka,Bangladesh
 Contact:
10038
I dont understand why do I get WA . Can any one check this code plz:
[c]
#include<stdio.h>
#include<stdlib.h>
void main(){
long int n,i,f1,f2,diff,bool,array[3005]={0};
FILE *infile,*outfile;
infile=stdin;
outfile=stdout;
while(1){
if(feof(infile)) break;
fscanf(infile,"%ld",&n);
fscanf(infile,"%ld",&f1);
for(i=0;i<n;i++)
array=0;
for(i=1;i<n;i++){
fscanf(infile,"%ld",&f2);
diff=abs(f1f2);
if (diff<n && diff>0)
array[diff]=1;
f1=f2;
}
bool=1;
for(i=1;i<n;i++){
if(array==0){
bool=0;
}
}
if (bool==0)
fprintf(outfile,"Not Jolly\n");
else
fprintf(outfile,"Jolly\n");
}
}[/c]
[c]
#include<stdio.h>
#include<stdlib.h>
void main(){
long int n,i,f1,f2,diff,bool,array[3005]={0};
FILE *infile,*outfile;
infile=stdin;
outfile=stdout;
while(1){
if(feof(infile)) break;
fscanf(infile,"%ld",&n);
fscanf(infile,"%ld",&f1);
for(i=0;i<n;i++)
array=0;
for(i=1;i<n;i++){
fscanf(infile,"%ld",&f2);
diff=abs(f1f2);
if (diff<n && diff>0)
array[diff]=1;
f1=f2;
}
bool=1;
for(i=1;i<n;i++){
if(array==0){
bool=0;
}
}
if (bool==0)
fprintf(outfile,"Not Jolly\n");
else
fprintf(outfile,"Jolly\n");
}
}[/c]

 Experienced poster
 Posts: 154
 Joined: Sat Apr 17, 2004 9:34 am
 Location: EEE, BUET
The problem lies in the way you are pursing the input. The input is not terminating & ultimately resulting in a WA.
Use 
[c]
while(fscanf(infile,"%ld",&n)!=EOF)
{
fscanf(infile,"%ld",&f1);
.....
.....
}
[/c]
& don't forget to change the Not Jolly to Not jolly in the printf().
Use 
[c]
while(fscanf(infile,"%ld",&n)!=EOF)
{
fscanf(infile,"%ld",&f1);
.....
.....
}
[/c]
& don't forget to change the Not Jolly to Not jolly in the printf().
Last edited by Mohammad Mahmudur Rahman on Sun Nov 14, 2004 6:21 pm, edited 1 time in total.
You should never take more than you give in the circle of life.

 New poster
 Posts: 4
 Joined: Sat Nov 13, 2004 12:17 pm
 Location: Dhaka,Bangladesh
 Contact:
Thanku
Thank you. I got AC. It was really a "Easy Jhamela Problem" for me. Thank you very much.
Good Bye Ramadan
&
Happy EID

 Experienced poster
 Posts: 154
 Joined: Sat Apr 17, 2004 9:34 am
 Location: EEE, BUET

 Learning poster
 Posts: 77
 Joined: Fri Dec 17, 2004 11:06 am
 Location: East West University, Dhaka, Bangladesh
 Contact:
hmmm. Great Programmer and also Great Helper. Well done Sohel.
Please join The ACM Solver Group at Yahoo
http://groups.yahoo.com/group/acm_solver/
http://groups.yahoo.com/group/acm_solver/
10038
I do not test your code but i can suggest you to do all the irretation to find the distance between two number and check what they say to check the all distance (1 to n1)
by the way if the n=4
then the if the distance is 1 2 3 or 3 1 2 or 3 2 1 all is jolly
GOOD LUCK
by the way if the n=4
then the if the distance is 1 2 3 or 3 1 2 or 3 2 1 all is jolly
GOOD LUCK