Problem description

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
解题思路:题目的意思就是输入的字符串中如果有相同的字符,去掉相同的字符,保留其中一个就好,保证序列中不出现相同的字符,问一共去掉多少个字符。简单处理字符串。
AC代码:
 #include<bits/stdc++.h>
using namespace std;
int main(){
int n,i=,sum=,num=;char str[];
cin>>n;getchar();//吃掉回车符对字符串的影响
cin>>str;
while(str[i]!='\0'){
if(str[i+]==str[i]){
while(str[i+]==str[i]){num++;i++;}
}
else {sum+=num;num=;i++;}
}
cout<<sum<<endl;
return ;
}

C - Stones on the Table的更多相关文章

  1. [LeetCode] Nim Game 尼姆游戏

    You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...

  2. [leetcode] 数字游戏

    169. Majority Element Given an array of size n, find the majority element. The majority element is t ...

  3. LeetCode 292. Nim Game

    Problem: You are playing the following Nim Game with your friend: There to stones. The one who remov ...

  4. 292. Nim Game

    292. Nim Game You are playing the following Nim Game with your friend: There is a heap of stones on ...

  5. Nim Game,Reverse String,Sum of Two Integers

    下面是今天写的几道题: 292. Nim Game You are playing the following Nim Game with your friend: There is a heap o ...

  6. Nam Game

    哪一方最终给对方留下4的倍数个石头则win,即想方设法的给对方留下4的倍数个石头. 例如: 9(B win) A:3 B:2(B取2,给对方余4,对方则lose) A:1 | 2 | 3 B:3 | ...

  7. lleetcode 292. Nim Game

    You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...

  8. Codeforces Round #163 (Div. 2)

    A. Stones on the Table \(dp(i)\)表示最后颜色为\(i\)的最长长度. B. Queue at the School 模拟. C. Below the Diagonal ...

  9. LN : leetcode 292 Nim Game

    lc 292 Nim Game 292 Nim Game You are playing the following Nim Game with your friend: There is a hea ...

随机推荐

  1. windons共享的一些问题

    有时候访问共享一直说无法打开共享,但是别人确实是开了共享. 其中可能如下: 1.首先确定网络没有问题,win+R输入cmd,ping对方IP地址,保证是网络是通的,如果不通,关闭共享电脑的防火墙. 2 ...

  2. mysql异地备份方案经验总结

    Mysql 数据库异地备份脚本 实验环境:关闭防火墙不然不能授权登录 Mysql-server:192.168.30.25 Mysql-client:  192.168.30.24 实验要求:对mys ...

  3. 【第8篇】:Python之面向对象

    python之--------封装 一.封装: 补充封装: 封装: 体现在两点: 1.数据的封装(将数据封装到对象中) obj = Foo('宝宝',22) 2.封装方法和属性,将一类操作封装到一个类 ...

  4. Vue源码学习(二)——生命周期

    官网对生命周期给出了一个比较完成的流程图,如下所示: 从图中我们可以看到我们的Vue创建的过程要经过以下的钩子函数: beforeCreate => created => beforeMo ...

  5. Leetcode 48.旋转矩阵

    旋转矩阵 给定一个 n × n 的二维矩阵表示一个图像. 将图像顺时针旋转 90 度. 说明: 你必须在原地旋转图像,这意味着你需要直接修改输入的二维矩阵.请不要使用另一个矩阵来旋转图像. 示例 1: ...

  6. noip模拟赛 拼不出的数

    分析:如果每个数可以选任意多次,那么就是一个很普通的dp问题,这里每个数只能选一次,还是考虑dp,设f(i)表示1~i是否都能选上.考虑下一个数j,如果j > i + 1,那么i+1这个数就选不 ...

  7. BZOJ1191 超级英雄Hero (匈牙利算法)

    直接跑匈牙利,注意到“只有当选手正确回答一道题后,才能进入下一题,否则就被淘汰”,一旦无法满足就直接退出. #include <cstdio> #include <algorithm ...

  8. HBase行键的设计

    rowkey是行的主键,而且hbase只能用rowkey范围即scan来查找数据.rowkey是以字典排序的.可以巧妙设计行键,比如想通过电影的评价进行排序,可以把评分rate和电影id组合起来,ra ...

  9. centos7 yum源

    https://www.cnblogs.com/muyunren/p/7221505.html https://www.cnblogs.com/renpingsheng/p/7845096.html

  10. U - Palindrome Manacher

    Andy the smart computer science student was attending an algorithms class when the professor asked t ...