Stones on the Table
来源:互联网 发布:ico图标制作软件 编辑:程序博客网 时间:2024/05/16 02:02
A. Stones on the Table
time limit per test
2 secondsmemory limit per test
256 megabytesinput
standard inputoutput
standard outputThere 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
3RRG
output
1
input
5RRRRR
output
4
input
4BRBG
output
0
#include "stdio.h"#include "string.h"#define N 51int main(){char s[N];int n,i;scanf ("%d",&n);int count=0;scanf ("%s",s);for (i=0;i<n-1;i++){if (s[i]==s[i+1])//判断相邻的石头颜色是否相同 count++;}printf ("%d\n",count); }
0 0
- Stones on the Table
- Stones on the Table
- A. Stones on the Table
- coderforces Stones on the Table
- CF - 266A - Stones on the Table
- CodeForces 266A Stones on the Table
- A - Stones on the Table (hdu)
- CodeForces-266A-Stones on the Table
- 266A - Stones on the Table
- 266A - Stones on the Table
- CodeForces 266A Stones on the Table
- CF 266A Stones on the Table
- codeforces 266A Stones on the Table
- Problem--266A--Codeforces--Stones on the Table
- 小白题解 Codeforces 266A Stones on the Table
- codeforces 266A(Stones on the Table) Java
- CodeForces 266 A.Stones on the Table(水~)
- Codeforces Round #163 (Div. 2) / 226A Stones on the Table (字符串处理)
- java多线程之Future和FutureTask
- SpringMVC接收页面表单参数
- React Native 之 Using a ListView
- vb中函数的调用与参数的传递
- ASP.NET MVC 5– 使用Wijmo MVC 5模板1分钟创建应用
- Stones on the Table
- C++程序员学习go基础语法
- Unity3D自学笔记——UGUI背包系统(一)ItemData
- Dagger2-渐入二(提升)
- win10里面f1到f12的快捷键为什么用不了?——纪念初学电脑和编程的傻逼
- 【龙印】龙芯1c上双路16位AD芯片TM7705的linux驱动
- mysql的group by用法在5.7和5.6中存在区别
- 遍历文件夹目录
- c++ time.h clock()程序计时