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:
Is PAT&TAP symmetric?
Sample Output:
11
题意
求最长回文串的长度。
思路
动态规划写法。具体总结待整理//TODO大法。
要注意fgets需要读取到换行符,所以fgets的最大长度需要比一行的字符数多1,否则读取不到换行符会出错。
代码
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAX_N 1000
using namespace std;
char s[