Skip to content

Instantly share code, notes, and snippets.

@gamazeps
Created December 5, 2017 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gamazeps/0bca4b45b1fe72ca8e5b70baba7f50e0 to your computer and use it in GitHub Desktop.
Save gamazeps/0bca4b45b1fe72ca8e5b70baba7f50e0 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <climits>
using namespace std;
int main() {
string buff;
vector<int> in;
while(getline(cin, buff)) {
istringstream iss(buff);
int tmp;
iss >> tmp;
in.push_back(tmp);
}
int pos(0);
int steps(0);
do {
int tmp(in[pos]);
steps+=1;
if (in[pos] > 2) {
in[pos]--;
} else {
in[pos]++;
}
pos += tmp;
} while (pos < in.size());
cout << steps << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment