Advertisement
askarulytarlan

Санта клаус и его робот

Jan 8th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <string.h>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. int n;
  10. string s;
  11. int ans = 0;
  12. cin >> n >> s;
  13. int x,y;
  14. x = y = 0;
  15.  
  16. for (int i = 0; i < n; i++) {
  17. if (s[i] == 'L' || s[i] == 'R') {
  18. if (x != 0 && x != s[i]) {
  19. ans++;
  20. y = 0;
  21. }
  22. x = s[i];
  23. }
  24. else {
  25. if (y != 0 && y != s[i]) {
  26. ans++;
  27. x = 0;
  28. }
  29. y = s[i];
  30. }
  31. }
  32.  
  33. cout << ans + 1;
  34.  
  35. return 0;
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement