博客
关于我
强烈建议你试试无所不能的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/

你可能感兴趣的文章
走进JavaWeb技术世界9:Java日志系统的诞生与发展
查看>>
走进JavaWeb技术世界10:从JavaBean讲到Spring
查看>>
走进JavaWeb技术世界11:单元测试框架Junit
查看>>
走进JavaWeb技术世界12:从手动编译打包到项目构建工具Maven
查看>>
走进JavaWeb技术世界13:Hibernate入门经典与注解式开发
查看>>
走进JavaWeb技术世界14:Mybatis入门
查看>>
走进JavaWeb技术世界16:极简配置的SpringBoot
查看>>
初探Java设计模式1:创建型模式(工厂,单例等)
查看>>
初探Java设计模式2:结构型模式(代理模式,适配器模式等)
查看>>
初探Java设计模式3:行为型模式(策略,观察者等)
查看>>
初探Java设计模式4:一文带你掌握JDK中的设计模式
查看>>
初探Java设计模式5:一文了解Spring涉及到的9种设计模式
查看>>
Java集合详解1:一文读懂ArrayList,Vector与Stack使用方法和实现原理
查看>>
Java集合详解2:一文读懂Queue和LinkedList
查看>>
Java集合详解3:一文读懂Iterator,fail-fast机制与比较器
查看>>
Java集合详解4:一文读懂HashMap和HashTable的区别以及常见面试题
查看>>
Java集合详解5:深入理解LinkedHashMap和LRU缓存
查看>>
Java集合详解6:这次,从头到尾带你解读Java中的红黑树
查看>>
Java集合详解7:一文搞清楚HashSet,TreeSet与LinkedHashSet的异同
查看>>
Java集合详解8:Java集合类细节精讲,细节决定成败
查看>>