-
Notifications
You must be signed in to change notification settings - Fork 6
/
hdu3068.cpp
71 lines (55 loc) · 918 Bytes
/
hdu3068.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<deque>
#include<limits.h>
#include<bitset>
#include<ctime>
#define deb(x) cout<<"#---"<<#x<<"=="<<x<<endl
using namespace std;
const long double PI=acos(-1.0);
const long double eps=1e-6;
const long long maxw=1e17+10;
typedef long long ll;
typedef pair<int,int> pii;
/*head------[@cordercorder]*/
const int maxn=110000+10;
char s[maxn];
int nxt[maxn],len;
void pre_kmp(){
int i=0,j=-1;
nxt[0]=-1;
while(i<len){
if(j==-1||s[i]==s[j]){
i++;
j++;
nxt[i]=j;
}
else{
j=nxt[j];
}
}
}
void solve(){
pre_kmp();
for(int i=1;i<=len;i++){
printf("%d ",nxt[i]);
}
puts("");
}
int main(void){
while(scanf("%s",s)!=EOF){
len=strlen(s);
solve();
}
return 0;
}