来宾住房和城乡建设局网站,青海格尔木建设局网站,百度企业信用,怎么申请网址怎么用题干#xff1a;
给定一个字符串S#xff0c;每次操作你可以将其中任意一个字符修改成其他任意字符。
请你计算最少需要多少次操作#xff0c;才能使得S中不存在两个相邻的相同字符。
Input
只包含小写字母的字符串S。
1 ≤ |S| ≤ 100000
Output
一个整数代表答案…题干
给定一个字符串S每次操作你可以将其中任意一个字符修改成其他任意字符。
请你计算最少需要多少次操作才能使得S中不存在两个相邻的相同字符。
Input
只包含小写字母的字符串S。
1 ≤ |S| ≤ 100000
Output
一个整数代表答案
Sample Input
aab
Sample Output
1
解题报告 考虑对于s[i]字符如果改变则会影响到s[i-1] 和 s[i1]所以我们考虑aab和aaa的情况。不难发现我们改变中间那个字符为任意值就可以了。。。
AC代码
#includecstdio
#includeiostream
#includealgorithm
#includequeue
#includemap
#includevector
#includeset
#includestring
#includecmath
#includecstring
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX 2e5 5;
char s[MAX];
int main()
{int ans 0;cins;int len strlen(s);for(int i 0; ilen; i) {if(s[i] s[i1]) {s[i1] ;ans;}} printf(%d\n,ans);return 0 ;}