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. CSS 选择器 知识点

    <html> <head> <style type="text/css"> h1 > strong { /*子元素选择器 只选择自己 的子 ...

  2. Linux之网络文件共享服务(FTP)

    一.FTP概念 •File Transfer Protocol 早期的三个应用级协议之一 •基于C/S结构 •双通道协议:数据和命令连接 •数据传输格式:二进制(默认)和文本  •两种模式:服务器角度 ...

  3. 关于PyQt5,在pycharm上的安装步骤及使用技巧

    前序 之前学习了一款GUI图形界面设计的Tkinter库,但是经大佬的介绍,PyQT5全宇宙最强,一脸的苦笑 毫不犹豫的选择转战PyQT5,在学习之前需要先安装一些必须程序,在一番查阅后,发现PyQt ...

  4. PatentTips – RDMA data transfer in a virtual environment

    BACKGROUND Embodiments of this invention relate to RDMA (remote direct memory access) data transfer ...

  5. hibernate之一对多映射

    目录 第一章 课程简介 第二章 Hibernate中的单向一对多关联 2-1 一对多映射简介 2-2 hibernate的基础配置 2-3 创建HibernateUtil工具类 2-4 在mysql数 ...

  6. A java code

    With the help of LiJun I got a piece of JAVA code. With this code, I can do below things like connec ...

  7. JEval使用实例

    jeval是为为你的Java应用程序提供可增加的.高性能.数学.  布尔和函数表达式的解析和运算的高级资源包. 以下这个样例包括了JEval经常使用功能: package demo0; import ...

  8. Smobiler实现列表展示—GridView(开发日志十二)

    一.列表功能展示   二.具体步骤 2.1,列表控件设计部分 2.1-① 在窗口SmoiblerForm1中加入gridview控件   2.1-② 在属性栏设置gridview控件的大小和位置   ...

  9. Ubuntu14.04下Android系统与应用开发软件完整apt-get 源。

    # deb cdrom:[Ubuntu 14.04.1 LTS _Trusty Tahr_ - Release amd64 (20140722.2)]/ trusty main restricted# ...

  10. Oracle学习(一):基本操作和基本查询语句

    文中以"--"开头的语句为凝视,即为绿色部分 1.知识点:能够对比以下的录屏进行阅读 SQL> --录屏工具spool,開始录制,并指定保存路径为c:\基本查询.txt SQ ...