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
Morae Q!
- Conversion of days into year, weeks and days.
- Find if the number is a perfect number or not.
- Compute conversion of Binary to Octal.
- Return the sum of digits in a number.
- Find if a word exists or not in a sentence.
- Convert Numbers into Words.
- Read a word if it consists only of the letters known.
- Check if the string is a dynamic string or not.
- Convert all Uppercase letters to Lowercase and vice-versa.
- Change the string such that there are no matching adjacent characters.
- Find the number of sub-strings which start and end both in 1.
- Find the start and end index of unsorted sub-array.
- Find the maximum number of pairs that can be formed.
- Figure out the number of bubbly words present.
- Check if a string is lapindrome or not even with a middle character.
- Seating layout in a triangular shaped class according to the number of rows.
- Find and Sort a sub-array which makes whole array sorted.
- Seating layout according to the number of rows.
- Find the final states of the bulbs.
- Check if reversing sub array makes the array sorted.