天天看點

POJ2406Power Strings

來源: 

power strings

time limit: 3000ms

memory limit: 65536k

total submissions: 30293

accepted: 12631

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

sample output

hint

this problem has huge input, use scanf instead of cin to avoid time limit exceed.

source

題意:不多解釋

這題書上說是用kmp來做,自己開始也嘗試這樣做,但後來發現根本就沒有這個必要~~~幾個簡單的字元串處理函數就可以a掉了

代碼: