#include<iostream>
#define LENGTH 9
char data[]="acabaabaabcacaabc";
char comp[]="abaabcac";
int pre[8];
void Compute_Prefix_Function()
{
int p=0;
pre[0]=0;
for(int i = 1; i < sizeof(comp) - 1; i++ ) {
while(p > 0 && comp[p] != comp[i])
p = pre[p-1];
if(comp[p] == comp[i])
p++;
pre[i] = p ;
}
for(int i = 0; i< 8 ; i++)
std::cout<<pre[i]<<" ";
}
void Compare_data()
{
Compute_Prefix_Function();
int i = 0;
int p = 0; int pp;
while(i < sizeof(data) - 1) {
while(p > 0 && comp[p] != data[i])
p = pre[p-1];
if(comp[p] == data[i])
p++;
if( p == sizeof(comp) -1) {
for(int j = i - p +1; j <= i; j++)
std::cout<<data[j];
return ;
}
//p = pre[]
//std::cout<<": p="<<p<<" i="<<i<<std::endl;
//std::cin>>pp;
i++;
}
}
int main()
{
Compare_data();
//Compute_Prefix_Function();
return 0;
}