String Protocol Solution || Codechef Starters - 29

           

String Protocol Solution 

Codechef Starters - 29
Problem Code : STRP

Solution :

#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
using namespace std;

void solve()
{
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = 0, i = 0;
    while (i < n)
    {
        if (s[i] == s[i + 1])
        {
            ans++;
            i += 2;
        }
        else
        {
            ans++;
            i++;
        }
    }
    cout << ans << "\n";
}

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

Comments