Square Substring
Time limit0.5sMemory limit1024 MB
Given a string S, find the longest substring of S whose first half equals its second half, and print it.
- Level
Medium5 of 10
- Topics
- Dynamic programming, String
- Solved
- No attempts yet
Problem
A string of length is called a square string if its prefix of length and its suffix of length are equal. The empty string is a square string.
Given a string , print the longest string that is both a substring of and a square string. A substring of is a string obtained by removing some characters from without changing the order of the remaining characters.
Input
The first line contains the number of test cases .
Each of the next lines contains a string . consists only of lowercase English letters.
The length of each string is between 1 and 3000, inclusive. The total length of all given strings is at most 3000.
Output
For each test case, print the answer as follows.
If the answer is the empty string, print Case #T: 0 on one line.
If the answer is not the empty string, print Case #T: L on the first line, and print the answer on the next line.
Here is the test case number (starting from 1), and is the length of the answer.