2021-07-15 AcWing 3768. 字符串删减
输入样例1:
6 xxxiii
输出样例1:
1
输入样例2:
5 xxoxx
输出样例2:
0
输入样例3:
10 xxxxxxxxxx
输出样例3:
8
双指针
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n;
int res=0;
string s;
cin >> n >> s;
for(int i=0; i < n; i++)
{
if(s[i]!='x') continue;
int j=i+1;
while(j<n && s[j]=='x'){
j++;
}
res += max(0,j-i-2);
i = j-1;
}
cout << res;
return 0;
}
本文来自博客园,作者:泥烟,CSDN同名, 转载请注明原文链接:https://www.cnblogs.com/Knight02/p/15799169.html