Why this code don't solved in Programming-challenge.com

This Problem name "Jolly Jumper"
please help me . i try to submit but it wrong answer

#include<iostream>
#include<cmath>

using namespace std;

bool JJump(int dif[] , int n){
for(int i =0 ; i < n-1; i++){

if( dif[i] == 0 || dif[i] >=n ){
return false;
}
}
return true;


}
int main(){

int num[2999];
int diff[2999];
int a;
int i = 0;

while(cin >> a){
i = 0;
for(i = 0 ; i < a ; i++){
cin >> num[i];
}

for(int j =0 ; j < a; j++){


diff[ j-1 ] = fabs( num[ j-1 ]-num[ j ] );

}

if( JJump(diff,a) ){

cout << "Jolly" ;
}
else{
cout << "Not jolly" ;
}
cout << endl;

}

return 0;
}
Last edited on
First, please use code tags when posting code. See http://www.cplusplus.com/articles/jEywvCM9/

You have two out of range errors in array deferencing statement.
There's some test cases here:
http://utexas.class.cs315.narkive.com/Xrs26nYi/jolly-jumpers-tests
Start with those posted by David Li. The others seem ok, but some of the counts are missing.
Topic archived. No new replies allowed.