Codeforces Problem-266A Stones on the Table
基本思想:
相邻的两块石头颜色相同,就要拿走其中一块,保证最后的石头序列相邻两个石头颜色不同。
依次比较相邻两块石头的颜色,如果相同则ans+1。
AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
string s;
cin>>n;
cin>>s;
int ans=0;
for (int i=1;i<n;i++)
{
if (s[i]==s[i-1])
ans++;
}
cout<<ans<<endl;
return 0;
}