CF978B File Name

    • 91通过
    • 132提交
  • 题目来源 CodeForces 978B
  • 评测方式 RemoteJudge
  • 标签
  • 难度 入门难度
  • 时空限制 1000ms / 256MB

题解

  • 提示:收藏到任务计划后,可在首页查看。
  • 最新讨论 显示

    推荐的相关题目 显示

    题意翻译

    当Polycarp试图在社交网络“Codehorses”发送文件时,他遇到了意想不到的问题。如果该文件的名称在一行中包含三个或更多x,则系统认为文件内容与社交网络主题不符。在这种情况下,文件会被和谐。

    确定要从文件名中删除的最少字符数,以便名称不包含xxx。如果文件名最初不包含子字符串xxx,则打印0

    您可以删除任意位置的字符$($不一定是连续的$)$。如果删除一个字符,则字符串的长度会减少$1$。例如,如果从字符串exxxii中删除位置$2$中的字符,则结果字符串为exxii

    输入

    第一行包含整数$n$ $(3 \le n \le 100)$ - 文件名的长度。

    第二行包含一个长度为$n$的字符串,其中包含仅由小写字母组成的文件名。

    输出

    打印要从文件名中删除的最少字符数,以便该名称不包含xxx。如果最初文件名不包含子字符串xxx,则输出0

    由 @cplusplus 提供翻译

    题目描述

    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".

    输入输出格式

    输入格式:

    The first line contains integer $ n $ $ (3 \le n \le 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.

    输出格式:

    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.

    输入输出样例

    输入样例#1: 复制
    6
    xxxiii
    
    输出样例#1: 复制
    1
    
    输入样例#2: 复制
    5
    xxoxx
    
    输出样例#2: 复制
    0
    
    输入样例#3: 复制
    10
    xxxxxxxxxx
    
    输出样例#3: 复制
    8
    

    说明

    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.

    提示
    标程仅供做题后或实在无思路时参考。
    请自觉、自律地使用该功能并请对自己的学习负责。
    如果发现恶意抄袭标程,将按照I类违反进行处理。