Facebook
From Wasee Ahsan, 2 Months ago, written in C++.
Embed
Download Paste or View Raw
Hits: 185
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define INF (ll)1e16
  4. using namespace std;
  5.  
  6. const int MOD = 1e9 + 7;  // Removed "long long" after const int
  7.  
  8. int getCount(int x )
  9. {
  10.     int total =  0 ;
  11.  
  12.     while(x % 2 == 0 )
  13.     {
  14.         x /= 2 ;
  15.         total++ ;
  16.     }
  17.     return total ;
  18. }
  19.  
  20. int main() {
  21.  
  22.     int t = 1; cin >> t;
  23.  
  24.     while (t--) {
  25.    
  26.     ll n ; cin >> n ;
  27.     string s ; cin >> s ;
  28.  
  29.     ll cnt  = 0  ;
  30.  
  31.     if(s[0] != s[2 ] and s[1] != s[3])
  32.     {
  33.         cnt++ ;
  34.     }
  35.  
  36.     for(ll i = 1 ; i  < n - 1 ; i++)
  37.     {
  38.         if(s[i] != s[i-1] or s[i+1] != s[i+2])
  39.         {
  40.             cnt++ ;
  41.         }
  42.     }
  43. cout << cnt << endl ;
  44.     }
  45.  
  46.     return 0;
  47. }
  48.