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 either leg needs to move
  23. if (currentPosition[0] != nextPosition[0]) {
  24. minMoves++;
  25. }
  26. if (currentPosition[1] != nextPosition[1]) {
  27. minMoves++;
  28. }
  29.  
  30. currentPosition = nextPosition;
  31. }
  32.  
  33. cout << minMoves << endl;
  34.  
  35. return 0;
  36. }
Success #stdin #stdout 0s 5284KB
stdin
6

down

right

down

up

right

down
stdout
10