3739.Stones on the Table

Time Limit: 1s Memory Limit: 256MB

There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.

Input Format(From the terminal/stdin)

The first line contains integer n (1 \le n \le 50) - the number of stones on the table.

The next line contains string s, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to n from left to right. Then the i-th character s equals "R", if the i-th stone is red, "G", if it's green and "B", if it's blue.

Output Format(To the terminal/stdout)

Print a single integer - the answer to the problem.

Sample Input 1

Copy
3
RRG
 \n
   \n

Sample Output 1

Copy
1
 \n

Sample Input 2

Copy
5
RRRRR
 \n
     \n

Sample Output 2

Copy
4
 \n

Sample Input 3

Copy
4
BRBG
 \n
    \n

Sample Output 3

Copy
0
 \n

Submit

请先 登录

© 2025 FAQs