Description
Given two strings a and b we define a*b to be their concatenation. For example, if a = "abc" and b = "def" then a*b = "abcdef". If we think of concatenation as multiplication, exponentiation by a non-negative integer is defined in the normal way: a^0 = "" (the empty string) and a^(n+1) = a*(a^n).Input
Each test case is a line of input representing s, a string of printable characters. The length of s will be at least 1 and will not exceed 1 million characters. A line containing a period follows the last test case.Output
For each s you should print the largest n such that s = a^n for some string a.Sample Input
abcd aaaa ababab .
Sample Output
1 43
題目大意:給出一個字符串,求這個串是有幾個子串構成的 思路:用KMP算法中的next數組,這個字符串的next數組裡邊,字符串的總長度減去最後一個字符所對應的next值就是子串的長度 具體為什麼,應該是next數組的值是根據這個字符串本身,用一定規則得出的,這個真的好巧妙的說,kmp算法,好好看看。 2014,12,5
#include#include char x[1100000]; int next[1100000]; void getnext(char s[]){ int len1,i,j; len1=strlen(s); i=0;j=-1; next[i]=j; while(i