Advertisement
Guest User

Untitled

a guest
Dec 25th, 2016
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. typedef pair< int, int > pii;
  6.  
  7. #define ff first
  8. #define ss second
  9. #define pb push_back
  10. #define mod 1000000007
  11.  
  12. int main(){
  13.  
  14.     int n;
  15.     string s;
  16.  
  17.     cin >> n;
  18.     cin >> s;
  19.  
  20.     int cnt= 0;
  21.  
  22.     for( int i= 0; i< n; ++i ){
  23.         set<char> st;
  24.         //cout << i << '\n';
  25.  
  26.         if( s[i]== 'L' ){
  27.             st.insert( s[i] );
  28.             i++;
  29.             while( i < n ){
  30.                 if( st.find('U')!= st.end() && s[i]== 'D' ){
  31.                     break;
  32.                 }else if( st.find('D')!= st.end() && s[i]== 'U' ){
  33.                     break;
  34.                 }else if( s[i]== 'R' ){
  35.                     break;
  36.                 }
  37.                 //cout << '\t' << s[i] << endl;
  38.                 i++;
  39.                 st.insert( s[i] );
  40.             }
  41.  
  42.         }else if( s[i]== 'R' ){
  43.             st.insert( s[i] );
  44.             i++;
  45.             while( i < n ){
  46.                 if( st.find('U')!= st.end() && s[i]== 'D' ){
  47.                     break;
  48.                 }else if( st.find('D')!= st.end() && s[i]== 'U' ){
  49.                     break;
  50.                 }else if( s[i]== 'L' ){
  51.                     break;
  52.                 }
  53.                 //cout << '\t' << s[i] << endl;
  54.                 i++;
  55.                 st.insert( s[i] );
  56.             }
  57.         }else if( s[i]== 'U' ){
  58.             st.insert( s[i] );
  59.             i++;
  60.             while( i < n ){
  61.                 if( st.find('L')!= st.end() && s[i]== 'R' ){
  62.                     break;
  63.                 }else if( st.find('R')!= st.end() && s[i]== 'L' ){
  64.                     break;
  65.                 }else if( s[i]== 'D' ){
  66.                     break;
  67.                 }
  68.                 //cout << '\t' << s[i] << endl;
  69.                 i++;
  70.                 st.insert( s[i] );
  71.  
  72.             }
  73.         }else{
  74.             st.insert( s[i] );
  75.             i++;
  76.             while( i < n ){
  77.                 if( st.find('L')!= st.end() && s[i]== 'R' ){
  78.                     break;
  79.                 }else if( st.find('R')!= st.end() && s[i]== 'L' ){
  80.                     break;
  81.                 }else if( s[i]== 'U' ){
  82.                     break;
  83.                 }
  84.                 //cout << '\t' << s[i] << endl;
  85.                 i++;
  86.                 st.insert( s[i] );
  87.             }
  88.         }
  89.         i--;
  90.         cnt++;
  91.  
  92.         //cout << i << endl << endl;;
  93.         st.clear();
  94.     }
  95.  
  96.     cout << cnt << endl;
  97.  
  98.     return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement