#include <cstdio>
#include <cstring>
char s[1000002 + 1200];
int fast(char *p)
{
int ans = 1;
for (int i = 1; p[i]; i++)
{
int s = i, e = i, t;
while (p[e+1] == p[i])
e++;
i = e;
while (p[s-1] == p[e+1])
s--, e++;
if ((t= e - s + 1) > ans)
ans = t;
}
return ans;
}
int main()
{
s[0]='$';
int n;
scanf("%d", &n);
while (n--)
{
scanf("%s", s + 1);
printf("%d\n", fast(s));
}
return 0;
}
最长回文子串
最新推荐文章于 2024-04-28 01:45:00 发布