266A. Stones on the Table

266A. Stones on the Table

  • time limit per test2 seconds
  • memory limit per test256 megabytes
  • inputstandard input
  • outputstandard output

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.

桌子上有n块石头排成一行,每一块都可以是红色、绿色或蓝色。计算从桌子上取下的石头的最小数量,以便相邻的任何两块石头具有不同的颜色。如果一排石头之间没有其他石头,则认为它们是相邻的。

Input

The first line contains integer n (1 ≤ n ≤ 50) — the number of stones on the table.

第一行包含整数n(1) ≤ N ≤ 50)-桌子上石头的数量。

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.

下一行包含字符串s,代表石头的颜色。我们将考虑从左到右编号为1到n的行中的石头。然后,第i个字符s等于“R”,如果第i个石头是红色的,则等于“G”,如果是绿色的,则等于“B”,如果是蓝色的。

Output

Print a single integer — the answer to the problem.

打印一个整数——问题的答案。

Examples
input1

3 RRG

output1

1

input2

5 RRRRR

output2

4

input3

4 BRBG

output3

0

Solution
Code
#include <iostream>
using namespace std;

//266A. Stones on the Table
#include <cctype>
int main() {
    string str;
    int n=0;
    cin>>n;
    cin >> str;
    int sum =0;
    for(int i=1;i<n;i++){
        int temp = str[i]-str[i-1];
        if(temp==0){
            sum++;
        }
    }
    cout<<sum<<endl;
}