首页 > 其他 > 详细

ACM模板 - 持续更新中

时间:2020-09-15 14:12:58      阅读:58      评论:0      收藏:0      [点我收藏+]

 KMP

 

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <algorithm>
 4 using namespace std;
 5 int nextt[1100000];
 6 int l;
 7 char s[1100000];
 8 void getnext(){
 9     int i=0,j=-1;
10     nextt[0]=-1;
11     while(i<l){
12         if(j<0||s[i]==s[j]){
13             nextt[++i]=++j;
14         }
15         else j=nextt[j];
16     }
17 }
18 
19 int main()
20 {
21     while(~scanf("%s",s)&&s[0]!=.){
22         l=strlen(s);
23         getnext();
24         int ans=1;
25         if(l%(l-nextt[l])==0)
26             ans=l/(l-nextt[l]);
27         printf("%d\n",ans);
28     }
29 }

 

ACM模板 - 持续更新中

原文:https://www.cnblogs.com/csx-zzh/p/13672517.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!