题意:桌子上有n个石子,每个石子的颜色为红、绿、蓝中的一种,问最少取掉多少个石子,使剩余的石子相邻的颜色都不同。
题目链接:http://codeforces.com/problemset/problem/266/A
——>>模拟题,扫描一次,若发现与上一个字符相同,计数器加1。
#include <cstdio>
using namespace std;
const int maxn = 50 + 10;
int main()
{
int n;
char s[maxn];
while(~scanf("%d", &n))
{
scanf("%s", s);
int cnt = 0;
for(int i = 1; i < n; i++)
if(s[i] == s[i-1]) cnt++;
printf("%d\n", cnt);
}
return 0;
}