include stdio include stdlib include string void prefix char int pr in

 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void prefix(char *p,int *pr)
{
int m=strlen(p);
pr[0]=0;
int k=0;
int q;
for(q=1;q<m;q++)
{
while((k>0)&&(p[k]!=p[q]))
{
k=pr[k-1];
}
if(p[k]==p[q])
{
k++;
}
pr[q]=k;
}
}
int main()
{
char s[100];
scanf("%s",&s);
int i,j,k,dl;
for(i=1;i<strlen(s);i++)
{
dl=i+1;
char *buf=malloc(dl*sizeof(char));
int *pref=malloc(dl*sizeof(int));
for(k=0;k<dl;k++)
{
buf[k]=s[k];
}
printf("a\n");
prefix(buf,pref);
j=dl-pref[i];
if((dl%j)==0)
{
printf("%d %d\n",dl,dl/j);
}
free(buf);
free(pref);
}
return 0;
}