我是靠谱客的博主 欣慰大叔,最近开发中收集的这篇文章主要介绍CodeForces 266A Stones on the Table,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

                                                              Stones on the Table
Time Limit:2000MS    Memory Limit:262144KB    64bit IO Format:%I64d & %I64u
SubmitStatusPracticeCodeForces 266A

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.

Sample Input

Input
3
RRG
Output
1
Input
5
RRRRR
Output
4
Input
4
BRBG
Output
0

解题思路:本题是经典是水题,只要看懂题目都能做。

题目意思:桌子上有一排石头,告诉你从左到右的石头的颜色(输入的字符串),要拿走一些石头,使桌子上相邻的石头颜色不同。给出左到右的石头的颜色,问你最少拿走多少个石头,使得排列满足题意。

输入数据后,直接从头到尾遍历即可,遇到后面紧跟的石头颜色和本石头颜色相同时,直接把石头拿走(记录个数),最后输出拿走的个数就可以了。


#include<stdio.h>
int main()
{
int n,i;
char a[60];
while(scanf("%d",&n)!=EOF)
{
scanf("%s",a);
int j=0;
for(i=0;i<n;i++)
if(a[i]==a[i-1])
//后面紧跟的石头颜色和本石头颜色相同
j++;
printf("%dn",j);
}
return 0;
}




最后

以上就是欣慰大叔为你收集整理的CodeForces 266A Stones on the Table的全部内容,希望文章能够帮你解决CodeForces 266A Stones on the Table所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(32)

评论列表共有 0 条评论

立即
投稿
返回
顶部