JosepRivaille

P77227: Salta, salta

Jun 5th, 2015
879
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. string sortida(int p, vector<int>& v) {
  6.        int tam = v.size();
  7.        vector<bool> aux(tam, false);
  8.        while(not aux[p]) {
  9.                  aux[p] = true;
  10.                  if (v[p] > 0) {
  11.                       if (p + v[p] >= tam) return "dreta";
  12.                       p += v[p];
  13.                  }
  14.                  else if (v[p] < 0) {
  15.                       if (p + v[p] < 0) return "esquerra";
  16.                       p += v[p];
  17.                  }
  18.        }  
  19.        return "mai";
  20. }
  21.  
  22. //JosepRivaille
Advertisement
Add Comment
Please, Sign In to add comment