"2012.07.11" the longest palindrome--horse-drawn vehicle algorithm

Source: Internet
Author: User

Total time limit:
10000ms
Single test point time limit:
1000ms
Memory Limit:
5120000kB
Describe

A string s consisting of a lowercase English character a,b,c...y,z is given, and the length of the longest palindrome in S is obtained.

Palindrome is the same as the inverse of the string, such as ABA, ABBA, etc.

Input
a file a set of data
string s consisting of one line of lowercase English characters for each set of input a,b,c...y,z
String length len <= 110000
Output
An integer x that represents the longest palindrome length contained in the string.
Sample input
AAAA-------------//Ignore split line Abab
Sample output
4-------------3


1 /*2 Naked Manache Consider three cases3 */4#include <cstdio>5#include <cstring>6#include <iostream>7 #defineMAXN 1100108 9 using namespacestd;Ten  One CharS[MAXN]; A  - intL,l,ans; -  the intt[maxn*3],len[maxn*3]; -  -Inlinevoidinit () { -t[l++]='$'; +t[l++]='#'; -      for(intI=0; i<l;i++) { +t[l++]=S[i]; At[l++]='#'; at     } -t[l]=0; -     return; - } -  -InlinevoidManache () { in     intp=0, p0=0; -      for(intI=1; i<=l;i++) { to         if(p>i) Len[i]=min (len[2*p0-i],p-i); +         Elselen[i]=1; -          while(T[i-len[i]]==t[i+len[i]]) len[i]++; the         if(len[i]+i>p) { *p=len[i]+i; $p0=i;Panax Notoginseng         } -Ans=max (ans,len[i]-1); the     } +     return; A } the  + intMain () { -      while(cin>>s) { $l=l=ans=0; $L=strlen (s); -         if(! L Break; - init (); the Manache (); -printf"%d\n", ans);Wuyi     } the     return 0; -}
Code

"2012.07.11" the longest palindrome--horse-drawn vehicle algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.