CF981A.Antipalindrome
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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…r] (1 ≤ l ≤ r ≤ ∣s∣) of a string s = s1s2…s∣s∣ is the string slsl + 1…sr.
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?
如果一个字符串从左到右读和从右到左读完全相同,则称其为回文串。例如,字符串 "kek"、"abacaba"、"r" 和 "papicipap" 都是回文串,而 "abb" 和 "iq" 则不是。
字符串 s=s1s2…s∣s∣ 的一个子串 s[l…r](其中 1 ≤ l ≤ r ≤ ∣s∣)定义为字符串 slsl + 1…sr。
安娜不喜欢回文串,因此让朋友们叫她“Ann”。她也会以类似方式修改所有她读到的单词:对每个单词 s,将其替换为最长的非回文子串;若 s 的所有子串都是回文串,则直接跳过该单词(即不作任何替换)。
不久前,Ann 读到了单词 s。她将这个单词改成了什么?
输入格式
The first line contains a non-empty string s with length at most 50 characters, containing lowercase English letters only.
第一行包含一个非空字符串 s,其长度最多为 50 个字符,且仅由小写英文字母组成。
输出格式
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.
如果字符串 s 中存在非回文子串,则输出其中最长的非回文子串的长度;否则输出 0。
注意:可能存在多个长度相同的最长非回文子串,但该长度值是唯一的。
输入输出样例
输入#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.
“mew” 不是回文串,因此它的最长非回文子串就是字符串 “mew” 本身。因此,第一个样例的答案是 3。
字符串 “uffuw” 是字符串 “wuffuw” 的最长非回文子串之一(长度为 5),因此第二个样例的答案是 5。
字符串 “qqqqqqqq” 的所有子串均由相同字符组成,因此它们都是回文串。因此,该字符串不存在非回文子串。于是,第三个样例的答案是 0。
输入解题思路,AI测评打分。不知道怎么写?