题意:为了不使连续的3个‘x’连续排列,需要删除多少个字符。
通过的代码:
#include<iostream>
#include<string>
using namespace std;
int main(){
ios::sync_with_stdio(false);cin.tie(0);
int n;cin>>n;string str;
cin>>str;int ans=0;
for(int i=2;i<n;i++)
if(str[i-1]=='x'&&str[i-2]=='x'&&str[i]=='x')ans++;
cout<<ans<<endl;
}