B - File Name

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

(3n100)

— 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
1
Input
5
xxoxx
Output
0
Input
10
xxxxxxxxxx
Output
8
Note

In the first example Polycarp tried to send a file with name contains number 33

, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.

AC代码(把每一组连续的x的个数记录下来,然后大于三的减去2就可以了)

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int i, n, a[120], h, f;
    char s[120];
    while(cin>>n)
    {
     h = 0, f = 0;
     int sm = 0;
     memset(a, 0, sizeof(a));
     cin>>s;
     for(i = 0;i<n;i++)
     {
      if(s[i]=='x')
      {
      a[h]++;
      f = 1;
      }
      else
      {
       if(f==1)
       {
        h++;
       }
       f = 0;
      }
     }
     h++;
     for(i = 0;i<h;i++)
     {
      if(a[i]>2)
      sm = sm + a[i]-2;
     }
     printf("%d\n",sm);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值