#C8927. Amazing String Transformation
Amazing String Transformation
Amazing String Transformation
You are given a string ( S ) of length ( n ). A string is called amazing if no two consecutive characters are identical. In one operation, you may change any character of the string to any other character (the new character can be any character, as long as it is different from its immediate neighbor).
Your task is to compute the minimum number of operations required to transform the given string into an amazing string. Formally, if there exists an index ( i ) (( 1 \leq i < n )) such that ( S_i = S_{i+1} ), you need to perform an operation on one of these characters. The goal is to ensure that for all ( i ) (( 1 \leq i < n )), ( S_i \neq S_{i+1} ).
For example, for ( n = 5 ) and ( S = \texttt{aabaa} ), the answer is 2 since you must change characters at two positions to break up the adjacent duplicates.
inputFormat
The input is read from the standard input and begins with an integer ( T ), which denotes the number of test cases. This is followed by ( T ) test cases. Each test case consists of a single line containing an integer ( n ) (the length of the string) and a string ( S ) separated by a space. It is guaranteed that ( |S| = n ).
For example:
3 5 aabaa 4 bbbb 6 abcdef
outputFormat
For each test case, print a single integer on a new line representing the minimum number of operations required to convert the string into an amazing string.## sample
3
5 aabaa
4 bbbb
6 abcdef
2
2
0
</p>