Hdu 4763 Theme Section (simple KMP)
Theme Section
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 1184 Accepted Submission (s): 621
Problem DescriptionIt's time for music! A lot of popular musicians are invited to join us in the music festival. each of them will play one of their representative songs. to make the programs more interesting and challenging, the hosts are going to add some constraints to the rhythm of the songs, I. e ., each song is required to have a 'Theme section '. the theme section shall be played at the beginning, the middle, and the end of each song. more specifically, given a theme section E, the song will be in the format of 'eaebe', where section A and section B cocould have arbitrary number of notes. note that there are 26 types of notes, denoted by lower case letters 'a'-'Z '.
To get well prepared for the festival, the hosts want to know the maximum possible length of the theme section of each song. Can you help us?
InputThe integer N in the first line denotes the total number of songs in the festival. each of the following N lines consists of one string, indicating the notes of the I-th (1 <= I <= N) song. the length of the string will not exceed 10 ^ 6.
OutputThere will be N lines in the output, where the I-th line denotes the maximum possible length of the theme section of the I-th song.
Sample Input
5xyabcaaaaaaabaaaxoaaaaa
Sample Output
00112
Source2013 ACM/ICPC Asia Regional Changchun Online
Given a string, search for three strings to make them completely equal (not overlapped). One must start from the beginning and the other must end with the end.
# Include "stdio. h "# include" string. h "# define N 1000005 char str [N], s [N]; int next [N], n; void getnext (int m) {int I = 0, j =-1; next [0] =-1; while (I