fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. int N;
  9. cin >> N;
  10.  
  11. vector<string> instructions(N);
  12. for (int i = 0; i < N; i++) {
  13. cin >> instructions[i];
  14. }
  15.  
  16. int minMoves = 0;
  17. string currentPosition = "down right"; // Initial position
  18.  
  19. for (int i = 0; i < N; i++) {
  20. string nextPosition = instructions[i];
  21.  
  22. // Check if a move is necessary for each leg
  23. if (currentPosition.find(nextPosition) == string::npos) {
  24. minMoves++;
  25. currentPosition = nextPosition + (currentPosition[1] != nextPosition[0] ? currentPosition[1] : nextPosition[0]);
  26. }
  27. }
  28.  
  29. cout << minMoves << endl;
  30.  
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
0