Stones on the Table

举报
辰chen 发表于 2022/06/15 00:06:12 2022/06/15
888 0 0
【摘要】 文章目录 一、Stones on the Table总结 一、Stones on the Table 本题链接:Stones on the Table 题目: A. Stones ...


一、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

本博客给出本题截图

在这里插入图片描述

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

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;
}

  
 

总结

水题,不解释

文章来源: chen-ac.blog.csdn.net,作者:辰chen,版权归原作者所有,如需转载,请联系作者。

原文链接:chen-ac.blog.csdn.net/article/details/117257940

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

作者其他文章

评论(0

抱歉,系统识别当前为高风险访问,暂不支持该操作

    全部回复

    上滑加载中

    设置昵称

    在此一键设置昵称,即可参与社区互动!

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。