Problem--266A--Codeforces--Stones on the Table

来源:互联网 发布:淘宝宝贝描述规则 编辑:程序博客网 时间:2024/05/16 14:45

Stones on the Tables

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.

Input
The first line contains integer n (1 ≤ n ≤ 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
Print a single integer — the answer to the problem.

Examples:
input
3
RRG
output
1

input
5
RRRRR
output
4

input
4
BRBG
output
0

#include<stdio.h>int main(){    int n,count=0;    scanf("%d",&n);    char stones[n+1];    scanf("%s",stones);    for(int i=0;i<n-1;i++)    {        if(stones[i]==stones[i+1])        count++;    }    printf("%d\n",count);    return 0;}
0 0
原创粉丝点击