Alternating Characters
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n;
cin>>n;
while(n--)
{
string str;
cin>>str;
int result=0;
for(int i=0;i<str.length()-1;i++)
{
if(str[i]==str[i+1])
result++;
}
cout<<result<<endl;
}
return 0;
}
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n;
cin>>n;
while(n--)
{
string str;
cin>>str;
int result=0;
for(int i=0;i<str.length()-1;i++)
{
if(str[i]==str[i+1])
result++;
}
cout<<result<<endl;
}
return 0;
}
Comments
Post a Comment