Menu Close

Change the string such that there are no matching adjacent characters.

Hassan is given a string containing characters A and B only.  Your task is to change it into a string such that there are no matching adjacent characters. 

To do this, you are allowed to delete zero or more characters in the string.
Your task is to find the minimum number of required deletions.

Input: 
The first line contain T, number of test cases.

Each test case contains a string s.

Output:
For each testcase, print the minimum number of deletions required on a new line.

Explanation:
For example, given the string 
               Input s = AABAAB 
(remove an A at positions 0 and 3 to make s=ABAB in 2 deletions)
               Output: 2
#include <stdio.h>
#include <string.h>
int main()
{int T,i;
scanf("%d",&T);
while(T--){
char s[100001];
int len,ans=0;
scanf("%s",s);
len=strlen(s);
for(i=0;i<len-1;i++){
    if(s[i]==s[i+1]){
        ans++;
    }
 }
 printf("%d\n",ans);
}

	return 0;
}

INPUT_1:
3
FAFAFAFA
GGGIII
GGGAFGA

OUTPUT:
0
4
2


INPUT_2:
5
GTUGTU
FAAFFA
TRTRTR
ERRERE
DFDGDF

OUTPUT:
0
2
0
1
0


ILLUSTRATION

Executed using gcc

Morae Q!