Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <string.h>
- #include <cstring>
- using namespace std;
- int main() {
- int n;
- string s;
- int ans = 0;
- cin >> n >> s;
- int x,y;
- x = y = 0;
- for (int i = 0; i < n; i++) {
- if (s[i] == 'L' || s[i] == 'R') {
- if (x != 0 && x != s[i]) {
- ans++;
- y = 0;
- }
- x = s[i];
- }
- else {
- if (y != 0 && y != s[i]) {
- ans++;
- x = 0;
- }
- y = s[i];
- }
- }
- cout << ans + 1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement