Page 6 of 30
Posted: Tue Oct 12, 2004 9:51 am
by sohel
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.

Posted: Tue Oct 12, 2004 2:07 pm
by hiro
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!!
Posted: Tue Oct 12, 2004 2:17 pm
by sohel
I'm not quite sure but I think there could be some extra lines in the judge's data after the very last case.
It is better to avoid getchar() and gets() when it's not needed.
Posted: Tue Oct 12, 2004 3:06 pm
by hiro
Thank you!!!
10038 Why RTE (Runtime Error)
Posted: Sat Oct 16, 2004 10:54 am
by habibiamin
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=Sequence-Sequence[j];
if(minus<0)minus*=-1;
if(minus>=1&&minus<=(n-1))
Jolly[minus]=0;
else
{r=0;break;}
}
for(i=1;i<=(n-1);i++)
if(Jolly==1)
{r=0;break;}
if(r)
printf("Jolly\n");
else
printf("Not jolly\n");
}
return 0;
}
[/cpp]
Posted: Sun Oct 17, 2004 9:56 am
by sohel
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. 
Posted: Sun Oct 17, 2004 12:21 pm
by habibiamin
Thanks dear sohel...
I do your suggestion and get WA

...I'll try to get AC
bye

10038
Posted: Sat Nov 13, 2004 12:26 pm
by simondhaka
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(f1-f2);
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]

10038
Posted: Sat Nov 13, 2004 12:27 pm
by simondhaka
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(f1-f2);
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]

Posted: Sat Nov 13, 2004 7:11 pm
by Mohammad Mahmudur Rahman
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().

Thanku
Posted: Sun Nov 14, 2004 12:59 am
by simondhaka
Thank you. I got AC. It was really a "Easy Jhamela Problem" for me. Thank you very much.
Good Bye Ramadan
&
Happy EID
Posted: Sun Nov 14, 2004 6:19 pm
by Mohammad Mahmudur Rahman
Nice to know that u've got AC.

Happy Eid to u 2.
Posted: Sat Dec 18, 2004 5:21 pm
by Niaz
hmmm. Great Programmer and also Great Helper. Well done Sohel.

Posted: Mon Dec 20, 2004 8:25 am
by jambon_vn
Man, I have the same problem.
I used cin.peek first and get WA. It is AC after changing to cin >> N.
Thank so much. However don't know what is going on.
10038
Posted: Thu Jan 06, 2005 6:04 am
by Rocky
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 n-1)
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