Stones on the Table

简介: Stones on the Table

文章目录

一、Stones on the Table

总结


一、Stones on the Table

本题链接:Stones on the Table


题目:


A. 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.


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


本博客给出本题截图:

image.png

题意:判断有多少个相邻的相同的色块。

AC代码

#include <iostream>
using namespace std;
const int N = 60;
char s[N];
int res; 
int main()
{
  int n;
  cin >> n;
  for (int i = 0; i < n; i ++ ) cin >> s[i];
  for (int i = 0; i < n - 1; i ++ )
    if (s[i] == s[i + 1]) 
      res ++;
  cout << res << endl;
  return 0;
}

总结

水题,不解释


目录
相关文章
|
8月前
|
索引
不推荐SELECT * FROM table原因
根据非索引查询 :B+树的叶子节点放数据表行数据,叶子节点存放主键,如果想获得行数据信息,则需要再跑到主键索引去拿数据,这叫回表,速度慢。但不管是主键还是非主键索引,他们的叶子结点数据都是有序的。比如在主键索引中,这些数据是根据主键id的大小,从小到大,进行排序的。**1.**根据索引查询 :B+树的父节点放索引数据,速度快,叶子(父)节点会存放完整的行数据西信息。
347 0
|
5月前
|
存储 SQL 关系型数据库
CREATE TABLE语句
在MySQL中,使用CREATE TABLE语句来创建表。你需要指定表名和列的定义,包括列名、数据类型以及约束等,结合实际存储和上一课学习的数据类型选取合适的。创建一个book_types表
156 0
|
7月前
|
数据库 OceanBase
使用 `INSERT INTO table_name SELECT * FROM table_name` 这种方式
使用 `INSERT INTO table_name SELECT * FROM table_name` 这种方式
45 1
|
8月前
|
数据库 OceanBase
INSERT INTO table_name SELECT * FROM table_name
INSERT INTO table_name SELECT * FROM table_name
37 1
|
JavaScript 前端开发 数据可视化
vxe-table
vxe-table
586 0
vxe-table
|
SQL 数据库
CREATE TABLE
CREATE TABLE
112 0
|
SQL 数据库
CREATE TABLE 语句
CREATE TABLE 语句
107 1
瞬表——Ephemeron Table
瞬表——Ephemeron Table
113 0
|
Java 索引
Table(表)
Table(表)
73 0
|
SQL Oracle 关系型数据库
SQL FOREIGN KEY Constraint on CREATE TABLE
SQL FOREIGN KEY Constraint on CREATE TABLE
64 1