Codeforces Round #481 (Div. 3) B. File Name

探讨了在社交网络“Codehorses”中发送文件时遇到的问题:如果文件名包含三个或更多连续的字母“x”,则被视为不符合主题。本文提供了一个简单的C语言程序来解决这一问题,即计算并输出移除最少数量的字符,使得文件名中不再出现“xxx”子串。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

B. File Name
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 11. For example, if you delete the character in the position 22 from the string "exxxii", then the resulting string is "exxii".

Input

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

The second line contains a string of length nn 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
Copy
6
xxxiii
output
Copy
1
input
Copy
5
xxoxx
output
Copy
0
input
Copy
10
xxxxxxxxxx
output
Copy
8
Note

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

, 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

题意:给你一段字符串,不能连续出现3个x,求最少删除多少个字符.

题解:用一个计数器计一下就好了

代码:

#include <stdio.h>
int  n,sum;
char a[110];
int rem[110];
int main()
{
	scanf("%d",&n);
	scanf("%s",a);
	sum =0;
	int p=0;
	memset(rem,1,sizeof(rem));
	for(int i=0;i<n;i++)
	{
		if(a[i]=='x')
			p++;
		else
			p=0;
		if(p==3)
		{
			sum++;
			p--;
		}
	}
	printf("%d\n",sum);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值