Help me in solving ROCPAPSCI problem

My issue

include <bits/stdc++.h>
using namespace std;

int main() {

int t;
cin>>t;
while(t–){
int n;
cin>>n;
string s;
cin>>s;
string check=“”;
for(int i=1;i<n-1;i++){
if(s[i]==s[i+1]|| s[i]==s[i-1]){

    if(i-1==0){
        check+=s[0];
    }
    else if(i+1==n-1){
        check+=s[n-1];
    }
    check+=s[i];
    
}

}

vectorcount(26);
int m=check.size();
for(int i=0;i<m;i++){
count[check[i]-‘A’]++;
}
int result=0;
for(int i=0;i<26;i++){
if(count[i]%2==0){
result+=(count[i]/2);
}
else{
result+=((count[i]+1)/2);
}
}
cout<<result+(n-m)<<endl;
}

return 0;
}
help me to solve this problem

My code

#include <bits/stdc++.h>
using namespace std;

int main() {
	
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string s;
cin>>s;
string check="";
for(int i=1;i<n-1;i++){
    if(s[i]==s[i+1]|| s[i]==s[i-1]){
        
        if(i-1==0){
            check+=s[0];
        }
        else if(i+1==n-1){
            check+=s[n-1];
        }
        check+=s[i];
        
    }
}

vector<int>count(26);
int m=check.size();
for(int i=0;i<m;i++){
    count[check[i]-'A']++;
}
int result=0;
for(int i=0;i<26;i++){
if(count[i]%2==0){
    result+=(count[i]/2);
}
else{
result+=((count[i]+1)/2);
}
}
cout<<result+(n-m)<<endl;
}


return 0;
}

Problem Link: Rock Paper Scissors Practice Coding Problem
strong text

@tejraj_2004
refer the following code for better understanding of the logic

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	   string s;
	   cin>>s;
	   int cnt=1;
	   int ans=0;
	   for(int i=1;i<n;i++)
	   {
	       if(s[i]==s[i-1])
	       {
	           cnt++;
	       }
	       else
	       {
	       ans+=(ceil(cnt*1.0/2.0));
	       cnt=1;
	       }
	   }
	   ans+=(ceil(cnt*1.0/2.0));
	   cout<<ans<<endl;
	}
	return 0;
}