A11860 | Antipalindrome
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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?
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.
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$ .
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted