fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. string x;
  8. cin >> x;
  9.  
  10. int position = 0;
  11. int min_position = 0, max_position = 0;
  12.  
  13. for (int i = 0; i < x.length(); i++) {
  14. if (x[i] == 'L') {
  15. position--;
  16. } else if (x[i] == 'R') {
  17. position++;
  18. }
  19.  
  20. if (position < min_position) {
  21. min_position = position;
  22. }
  23. if (position > max_position) {
  24. max_position = position;
  25. }
  26. }
  27.  
  28. cout << (max_position - min_position + 1) << endl;
  29.  
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0.01s 5276KB
stdin
RRSRRLRR
stdout
6