解题说明:此题是一道字符串题,确保不连续出现三个X即可。
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
int i, n, k = 0;
scanf("%d", &n);
char sr[104];
scanf("%s", sr);
for (i = 0; i<n - 2; i++)
{
if (sr[i] == 'x' && sr[i + 1] == 'x' && sr[i + 2] == 'x')
{
k++;
}
}
printf("%d\n", k);
return 0;
}