博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
第三题
阅读量:20606 次
发布时间:2019-12-03

本文共 986 字,大约阅读时间需要 3 分钟。

Stones on the Table

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.
问题简述:就是看输入的char中相邻的是否相同
程序说明:检查输入的char数组,第一个开始,检查有多少个第n个于第n+1个相同,
最后输出相同的次数
AC代码
#include
using namespace std;
int main()
{
int a;
char b[60];
cin >> a >> b;
b[a] = 0;
int i=0,take=0;
while (b[i])
{
char c;
c = b[i];
if (c == b[i + 1])
take++;
i++;
}
cout << take << endl;
}

转载地址:http://ogevfk.baihongyu.com/

你可能感兴趣的文章
L1-020 帅到没朋友 (20 分)
查看>>
L1-046 整除光棍 (20 分)
查看>>
L2-021 点赞狂魔 (25 分)【优化后的】
查看>>
L2-032 彩虹瓶 (25 分)
查看>>
L2-004 这是二叉搜索树吗? (25 分)
查看>>
[Error] ‘nullptr‘ was not declared in this scope解决方案
查看>>
L2-011 玩转二叉树 (25 分)
查看>>
L2-006 树的遍历 (25 分)
查看>>
L3-010 是否完全二叉搜索树 (30 分)
查看>>
6-10 阶乘计算升级版 (20 分)
查看>>
7-78 阅览室 (20 分)
查看>>
7-21 查验身份证 (15 分)
查看>>
实验4-1-5 韩信点兵 (10 分)
查看>>
1016 部分A+B (15 分)
查看>>
1023 组个最小数 (20 分)
查看>>
1036 跟奥巴马一起编程 (15 分)
查看>>
1002 写出这个数 (20 分)
查看>>
1010 一元多项式求导 (25 分)
查看>>
使用Python通过win32 COM接口实现Excel单元格写入
查看>>
使用命令行工具编译C#程序
查看>>