-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2752.cpp
52 lines (50 loc) · 851 Bytes
/
2752.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
#if 0
//KMP
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=400000+5;
char str[maxn];
int next[maxn];
int num[maxn];
void get_next()
{
int i=0,j=-1,len;
len=strlen(str);
next[i]=-1;
while(i<len)
{
if(j==-1||str[i]==str[j])
{
i++;
j++;
next[i]=j;
}
else
j=next[j];
}
}
int main()
{
//freopen("input.txt","r",stdin);
while(scanf("%s",str)!=EOF)
{
int len=strlen(str);
get_next();
int j=0;
for(int i=len;i!=0;i=next[i],j++)
{
num[j]=i;
}
for(int i=j-1;i>=0;i--)
{
if(i!=j-1)
printf(" ");
printf("%d",num[i]);
}
printf("\n");
}
return 0;
}
#endif // 1