#K12056. No Adjacent Duplicates
No Adjacent Duplicates
No Adjacent Duplicates
You are given a string s
. Your task is to determine the minimum number of insertions needed so that no two consecutive characters in the resulting string are identical. In other words, you need to count the number of positions where adjacent characters in the original string are the same.
The answer can be mathematically represented as follows:
\[ \text{Answer} = \sum_{i=1}^{n-1} \mathbf{1}_{\{s_i = s_{i+1}\}} \]
For example, for the string "aabb" the answer is 2, since there are two positions (between the two 'a's and the two 'b's) where the characters are identical.
inputFormat
The input consists of a single line containing the string s
(which may be empty). The string consists of printable characters.
outputFormat
Output a single integer which represents the minimum number of insertions required such that no two adjacent characters are identical.
## sampleaabb
2