[Solved] simulating pawn jump in the array/vector [closed]


#include <algorithm>

void myfunction (int &i) {  // function:
  i=1000001;
}

int arrayJmp ( const vector<int> &A ) {
    int N=A.size();

  vector<int> indexes;
  for_each (indexes.begin(), indexes.end(), myfunction);
  int index=0;

  while(std::find(indexes.begin(), indexes.end(), index) == indexes.end()){
    indexes.push_back(index);

    index+=A[index];
    if (index==(N-1)&&A[index]>0) return indexes.size()+1;
  }

  return -1;
}

9

solved simulating pawn jump in the array/vector [closed]