File Name(CF-978B)

Problem Description

You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed.

Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx".

You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by 1. For example, if you delete the character in the position 2 from the string "exxxii", then the resulting string is "exxii".

Input

The first line contains integer n (3≤n≤100) — the length of the file name.

The second line contains a string of length n consisting of lowercase Latin letters only — the file name.

Output

Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0.

Examples

Input

6
xxxiii

Output

Input

5
xxoxx

Output

0

Input

10
xxxxxxxxxx

Output

8

————————————————————————————————————————————

题意: 给出一长度为 n 的字符序列,要求不能存在连续的相邻的三个 " x ",如果存在,则删去1个 " x " 使其不连续,求要删除的 " x " 的个数。

思路:暴力枚举即可,从第一个枚举到第 n-2 个,如果相邻的3个字符都是 " x " ,计数器 +1 即可

Source Program

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<ctime>
#include<vector>
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define N 1000005
#define MOD 1e9+7
#define E 1e-6
typedef long long ll;
using namespace std;
string str;
int main()
{
    int n;
    cin>>n;
    cin>>str;

    int cnt=0;
    for(int i=0;i<n-2;i++)
        if(str[i]=='x'&&str[i+1]=='x'&&str[i+2]=='x')
            cnt++;

    cout<<cnt<<endl;

    return 0;
}

猜你喜欢

转载自blog.csdn.net/u011815404/article/details/81540854