CF981A Antipalindrome

    • 26通过
    • 42提交
  • 题目来源 CodeForces 981A
  • 评测方式 RemoteJudge
  • 标签 字符串 枚举,暴力
  • 难度 入门难度
  • 时空限制 1000ms / 256MB

题解

  • 提示:收藏到任务计划后,可在首页查看。
  • 体验新版界面

    最新讨论 显示

    推荐的相关题目 显示

    题意翻译

    给定一段字符串,求这段字符串中最长的不回文字符串

    题目描述

    A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.

    A substring $ s[l \ldots r] $ ( $ 1 \leq l \leq r \leq |s| $ ) of a string $ s = s_{1}s_{2} \ldots s_{|s|} $ is the string $ s_{l}s_{l + 1} \ldots s_{r} $ .

    Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $ s $ is changed into its longest substring that is not a palindrome. If all the substrings of $ s $ are palindromes, she skips the word at all.

    Some time ago Ann read the word $ s $ . What is the word she changed it into?

    输入输出格式

    输入格式:

    The first line contains a non-empty string $ s $ with length at most $ 50 $ characters, containing lowercase English letters only.

    输出格式:

    If there is such a substring in $ s $ that is not a palindrome, print the maximum length of such a substring. Otherwise print $ 0 $ .

    Note that there can be multiple longest substrings that are not palindromes, but their length is unique.

    输入输出样例

    输入样例#1: 复制
    mew
    
    输出样例#1: 复制
    3
    
    输入样例#2: 复制
    wuffuw
    
    输出样例#2: 复制
    5
    
    输入样例#3: 复制
    qqqqqqqq
    
    输出样例#3: 复制
    0
    

    说明

    "mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $ 3 $ .

    The string "uffuw" is one of the longest non-palindrome substrings (of length $ 5 $ ) of the string "wuffuw", so the answer for the second example is $ 5 $ .

    All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $ 0 $ .

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