fork download
  1.  
  2. #include <iostream>
  3. #include <vector>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. int N;
  10. cin >> N;
  11.  
  12. vector<string> instructions(N);
  13. for (int i = 0; i < N; i++) {
  14. cin >> instructions[i];
  15. }
  16.  
  17. int minMoves = 0;
  18. string currentPosition = "up right"; // Initial position
  19.  
  20. for (int i = 0; i < N; i++) {
  21. string nextPosition = instructions[i];
  22.  
  23. // Check if either leg needs to move
  24. if (currentPosition[0] != nextPosition[0]) {
  25. minMoves++;
  26. }
  27. if (currentPosition[1] != nextPosition[1]) {
  28. minMoves++;
  29. }
  30.  
  31. currentPosition = nextPosition;
  32. }
  33.  
  34. cout << minMoves << endl;
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0.01s 5280KB
stdin
6

down

right

down

up

right

down
stdout
12