#C4861. Avoiding Consecutive Duplicate Characters
Avoiding Consecutive Duplicate Characters
Avoiding Consecutive Duplicate Characters
You are given a string S
and you need to determine the minimum number of characters that must be removed such that no two identical characters appear consecutively in the resulting string.
More formally, if the string has a length n, you need to calculate the value
\(\sum_{i=2}^{n} \mathbf{1}\{S_i=S_{i-1}\}\)
where \(\mathbf{1}\{condition\}\) equals 1 if the condition is true and 0 otherwise.
This problem requires a simple iterative scan over the string to count occurrences of consecutive duplicates, and then output that count as the answer for each test case.
inputFormat
The first line of input contains an integer T
denoting the number of test cases.
Each of the following T
lines contains a non-empty string S
consisting of lowercase letters.
outputFormat
For each test case, output a single line containing the minimum number of removals required to ensure that no two identical consecutive characters remain in the string.
## sample3
abbab
aabb
abcde
1
2
0
</p>