fork(5) download
  1. #include <algorithm>
  2. #include <stdlib.h>
  3. #include <iostream>
  4. #include <stdio.h>
  5. #include <string>
  6. #include <vector>
  7. #include <set>
  8. #include <map>
  9.  
  10. #define all(c) c.begin(), c.end()
  11. #define sqr(c) ((c)*(c))
  12.  
  13. using namespace std;
  14.  
  15. int main() {
  16. string north, south;
  17. getline(cin, south);
  18. getline(cin, north);
  19. int i = 0, j = 0, timer = 0;
  20. while (i + j < north.length() + south.length()) {
  21. if (j < south.length()) {
  22. if (south[j] == 'F' || south[j] == 'R')
  23. j++;
  24. else
  25. if (i == north.length() || north[i] == 'L')
  26. j++;
  27. }
  28. if (i < north.length()) {
  29. if (north[i] == 'F' || north[i] == 'R')
  30. i++;
  31. else
  32. if (j == south.length() || south[j] == 'L')
  33. i++;
  34. }
  35. timer++;
  36. }
  37. cout << timer;
  38.  
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0s 3276KB
stdin
LLLLFR
RLRFRLLRLF
stdout
12