题意:就是从左往右放石头,但是不能让相同颜色的石头相邻,相邻的石头就移除,问要移除几个石头。
很简单的一题,但是一开始没看懂题意,以为是问最少移动几次使相邻石头颜色不同。
注意,不要认为最后一个和第一个颜色也要不同,这不是环。
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int n,i,sum;
char s[55];
while(scanf("%d",&n)!=EOF)
{
sum = 0; //移除石头数量
scanf("%s",&s);
for(i = 0; i < n; i++)
{
if(s[i] == s[i+1]) //判断当前的和后面的颜色是否相同,相同则移除
{
sum++;
}
}
printf("%d\n",sum);
}
return 0;
}