您的位置:首页 > 编程语言

超强悍的ac代码 PKU2406 百度搜的

2010-07-20 20:20 225 查看
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char str [1000010];
int next[1000010];

int getnext()
{
int i= 0, j= -1; next[0]= -1;

while( str[i] )
{
if( j== -1 || str[i]== str[j] )
{
++i,++j;
next[i]= j;
}
else j= next[j];
}

int len= strlen(str);
i= len- j;

if( len% i== 0 ) return len/ i;
else return 1;
}

int main()
{
while( gets( str), str[0]!= '.' )
printf("%d\n", getnext() );

return 0;
}

能看懂吗?哈哈。。。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐