题意:为了不使连续的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;
}
本文介绍了一个Codeforces上的编程题目B的解决方案。该题目要求计算为避免出现连续三个字符为‘x’的情况需要删除的字符数量。通过遍历字符串并检查特定条件来实现,最终输出所需的删除次数。
258

被折叠的 条评论
为什么被折叠?



