# ZOJ_1905_Power Strings 进击のkmp 原

電泡泡

Power Strings Time Limit: 5 Seconds       Memory Limit: 32768 KB

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.

Output

For each s you should print the largest n such that s = a^n for some string a. 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.

Sample Input

abcd
aaaa
ababab
.

Sample Output

1
4
3

``````#include <iostream>
#include <string>
using namespace std;

int next[1000002];
string str;
int len;

void get_next(string T, int next[])
{
int i,j;
next[1]=0;
j=0;i=1;
while(i<len)//不要等于m
{
if(j==0||T[i]==T[j]){
++i;
++j;//这个地方完全可以弄到m所以等于的时候不用继续循环
if(T[i]!=T[j])
next[i]=j;
else
next[i]=next[j];
}
else
j=next[j];
}
}

int
main()
{
while(cin>>str && str!="."){
len=str.length();
get_next(str, next);
if(len%(len-next[len])==0)
cout<<len/(len-next[len])<<endl;
else
cout<<"1"<<endl;
}
return 0;
}``````

### 電泡泡

poj 2406 Power Strings

kmp优化过的求next的方法不能直接用 aaaaababab. Sample Output 143 Hint [Submit] [Go Back] [Status] [Discuss] /*===================================================================......

locusxt
2013/12/21
0
0
Gym - 101164K Cutting 哈希+枚举

ACM-ICPC Southeastern European Regional Programming Contest Bucharest, Romania – Vinnytsya, Ukraine October 22, 2016 Problem K Cutting Input File: K.in Output File: standard o......

ProLightsfxjh
2017/07/25
0
0
Gym - 101164C Castle KMP的拓展、next数组+dp、好题

ACM-ICPC Southeastern European Regional Programming Contest Bucharest, Romania – Vinnytsya, Ukraine October 22, 2016 Problem C Castle Input File: C.in Output File: standard ou......

ProLightsfxjh
2017/07/25
0
0
jeecg3.7.8

processAnnotationsJndi 严重: Unable to process JNDI URL [jndi:/localhost/WEB-INF/classes/jeecg/ext-common-template/bootstrap/onetomany/java/%24%7BbussiPackage%7D] for annotatio......

10/15
197
1
Aho-Corasick automaton（AC自动机）解析及其在算法竞赛中的典型应用举例

Reqaw
08/11
0
0

13分钟前
1
0
vue路由传参，刷新页面，引发的bug

hanbb
13分钟前
0
0
【58沈剑 架构师之路】InnoDB，select为啥会阻塞insert？

MySQL的InnoDB的细粒度行锁，是它最吸引人的特性之一。 但是，如《InnoDB，5项最佳实践》所述，如果查询没有命中索引，也将退化为表锁。 InnoDB的细粒度锁，是实现在索引记录上的。 一，Inn...

16分钟前
0
0

/** * 冒泡排序，两层嵌套循环，内层局部比较后，找出最大或者最小数据并交换数据，使其局部有序，外层用于比较剩余元素，相较于选择排序，选择排序相当于是冒泡的一个优化版本（减少了交换...

strict_nerd
17分钟前
0
0
html内联（行内）元素、块级（块状）元素和行内块元素分类

HTML可以将元素分类方式分为内联（行内）元素、块级（块状）元素和行内块元素三种。 注：HTML是标签语言，那么既然是标签，就可以自己定义一些自己元素（如<wode>自定义的元素</wode>等），自...

NB-One
23分钟前
1
0