【题解】FZU-1901 Period II
Period II(FZU-1901)
题面
For each prefix with length P of a given string S,if
S[i]=S[i+P] for i in [0..SIZE(S)-p-1],
then the prefix is a “period” of S. We want to all the periodic prefixs.
输入
Input contains multiple cases.
The first line contains an integer T representing the number of cases. Then following T cases.
Each test case contains a string S (1 <= SIZE(S) <= 1000000),represents the title.S consists of lowercase ,uppercase letter.
输出
For each test case, first output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the number of periodic prefixs.Then output the lengths of the periodic prefixs in ascending order.
样例输入
1 | 4 |
样例输出
1 | Case #1: 3 |
提示
无
思路
类似【题解】POJ-2752 Seek the Name, Seek the Fame。对于字符串的所有前缀,若存在循环节,输出符合条件的前缀个数与这个前缀字符串的长度。注意输出格式,行尾不得有多余空格。
代码
1 | char t[mxn]; |