Source Code
#include <bits/stdc++.h>
#define clr(str , charr) memset(str,charr, sizeof(str))

typedef long long  ll;
typedef unsigned long long  ull;
using namespace  std;

bool isp(ll a)

{

  if (a == 2)return 1;
  if (a%2 == 0|| a==1)return false;

  for (ll i =3 ; i*i<=a ; i+=2)
  {
    if (a %i ==0)return false;
  }

  return true;
}


/* Function to calculate x raised to the power y in O(logn)*/
int power1(int x, unsigned int y)
{
	int temp;
	if( y == 0)
		return 1;
	temp = power1(x, y / 2);
	if (y % 2 == 0)
		return temp * temp;
	else
		return x * temp * temp;
}

/* Iterative Function to calculate (x^y) in O(logy) */
ll power2(ull x, ull y)
{
    ull res = 1; // Initialize result
 
    while (y > 0) {
        // If y is odd, multiply x with result
        if (y & 1)
            res = res * x;
 
        // n must be even now
        y = y >> 1; // y = y/2
        x = x * x; // Change x to x^2
    }
    return res;
}

void solve ()
{
  int n  , res=0;cin>>n;
  char a[n];
  for (int i=0 ; i<n ; ++i)cin>>a[i];

  for (int i=0 ; i<n-1 ; ++i){
    if (a[i]!= a[i+1]){res++; i++;}
  }
  cout << res;
}



ll fact(int n ){
  ll res=1;

  for (int i=2 ; i<=n ;++i)res*=i;
  return res;
}

void fast(){
 ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
}

ll Fact (int n){
  if (n<=1)return 1;
  return n*Fact(n-1);
}

void printnum(int n){
  if (n){
    printnum(n/10);
    cout << n %10;
  }
}

int main() 
{
  fast();
  //int t; cin>>t;
  //while(t--)
  solve();
}


Copy
Tha Bits The Legendary_Scar
GNU G++17
3 ms
752 KB
Accepted