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!!
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;}
}
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.
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().
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