ACM第三题

Text Reverse

Time limit2000 msMemory limit262144 kBSourceCodeforces Round #163 (Div. 2)Tagsimplementation *800EditorialAnnouncement Tutorial

Problem 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 input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.Each test case contains a single line with several words. There will be at most 1000 characters in a line.

Output
Print a single integer — the answer to the problem.

Sample Input
3
RRG

Sample Output
1

问题链接:https://vjudge.net/problem/CodeForces-266A

问题简述:桌面有排成一列且有三种颜色的石头,抽出其中相邻且颜色相同的一块,求要抽出几块。

问题分析:利用字符数组来储存,且一个一个比较。

程序说明:用for循环来决定比较次数,在循环内比较相同的就利用一个整型数加一储存拿出的次数。

AC通过的C语言程序如下:

#include <iostream>
using namespace std;
int main()
{
	int a, b, c=0;
	char A[100];
	cin >> a;
	cin >> A;
	for (b = 0; b < a; b++)
	{
		if (A[b] == '\0')break;
		else
			if (A[b] == A[b + 1])
				c++;
	}
	cout << c;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值