首页 > 其他 > 详细

Seek the Name, Seek the Fame

时间:2019-07-05 13:11:02      阅读:92      评论:0      收藏:0      [点我收藏+]

题面

啦啦啦,仍然是kmp

 1 #include<algorithm>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<cstdio>
 5 #include<cmath>
 6 #include<queue>
 7 using namespace std;
 8 char s[400001];
 9 int len,next[400001],sum[400001];
10 void get_next(int len){
11     int i=0,j=-1;
12     next[0]=-1;
13     while(i<len){
14         if((j==-1)||(s[i]==s[j])){
15             i++;
16             j++;
17             next[i]=j;
18         }
19         else{
20             j=next[j];
21         }
22     }
23 }
24 int main(){
25     while(scanf("%s",s)!=EOF){
26         int k=0;
27         len=strlen(s);
28         get_next(len);
29         for(int i=len;i!=0;){
30             sum[k++]=next[i];
31             i=next[i];
32         }
33         for(int i=k-2;i>=0;i--){
34             printf("%d ",sum[i]);
35         }
36         printf("%d\n",len);
37     }
38     return 0;
39 }

 

Seek the Name, Seek the Fame

原文:https://www.cnblogs.com/ainiyuling/p/11136942.html

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