Advertisement
amine99

Untitled

Feb 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define loop(i,b,e) for(int i=b;i<=e;i++)
  4. #define reloop(i,e,b) for(int i=e;i>=b;i--)
  5.  
  6. int n,ans,x,y,m=0,mpred;
  7. string s;
  8.  
  9. int main() {
  10.    cin >> n >> s;
  11.    int b;
  12.    loop(i,0,s.length()-1) {
  13.       if (s[i] == 'R')
  14.          x++;
  15.       else
  16.          y++;
  17.       if (x-y == 1 && b != 1) {
  18.          ans++;
  19.          b = 1;
  20.       }
  21.       if (y-x == 1 && b != 2) {
  22.          ans++;
  23.          b = 2;
  24.       }
  25.    }
  26.    cout << ans-1;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement