PTA甲级——1040
1040 Longest Symmetric String
Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given Is PAT&TAP symmetric?
, the longest symmetric sub-string is s PAT&TAP s
, hence you must output 11
.
Input Specification:
Each input file contains one test case which gives a non-empty string of length no more than 1000.
Output Specification:
For each test case, simply print the maximum length in a line.
Sample Input:
1 |
|
Sample Output:
1 |
|
思路
非常经典的一种类型的题目,寻找回文字串长度最大值类型题目,一般有O(n^3)、O(n^2)、O(n)、O(nlogn)四种经典办法来写,这里数据量为1000,因此使用第二种写法就ok了。
如果想看其他写法,可以看看这篇文章最长回文子串的四种解法
代码
1 |
|