标签:sys pac cst void ace poj string name ext
#include<iostream>
#include<cstring>
using namespace std;
int len;
void getNext(char *s, int *nex)
{
nex[0] = -1;
int i = 0, j = -1;
while(i < len)
{
if(j == -1 || s[i] == s[j])
{
i++, j++;
nex[i] = j;
}
else j = nex[j];
}
}
int main()
{
char s[1000100];
while(~scanf("%s", s))
{
getchar();
if(s[0] == ‘.‘) break;
//cout << s << endl;
len = strlen(s);
int nex[1000100];
getNext(s, nex);
int a = nex[len];
if(a*2 < len) printf("1\n");
else
{
if(len%(len-a) == 0) printf("%d\n", len/(len-a));
else printf("1\n");
}
}
//system("pause");
return 0;
}
标签:sys pac cst void ace poj string name ext
原文地址:https://www.cnblogs.com/znk97/p/14043961.html