Background
Tata is an intelligent robot, he can think like a person, but because of the IQ problem, he gave himself a long long name.
Describe
One day, Tata wanted to paint his name on the wall. Because his name was too long, for the sake of convenience, he intercepted a section of his name as a template. We may as well set the length of this template is L, Tata the length of the name is L, then there is 1≤l≤l. Then Tata will use this template for a number of spraying, squirting his name (the next spray will cover the results of the previous spray, such as the current wall already has ABC three characters, then if you spray at C, you will get ABABC). Tata spray name always from the front of the spray, assuming that Tata spraying K times, this K-spraying in chronological order the position of the first spraying is s[i], then s[i]
#include <cstdio> #include <cmath> #include <cstring> #include <
algorithm> #include <stack> #include <iostream> using namespace std;
Char t[1000100];
int Len;
int next[1000100];
int ans[1000100];
void Makenext () {next[1]=0;
int i=1,j=0; while (I<=len) {if (j==0| |
T[i]==t[j]) {i++;j++;
Next[i]=j;
} else j=next[j];
}} int main () {//freopen ("In.txt", "R", stdin);
scanf ("%s", t+1);
Len=strlen (t+1);
Makenext ();
int k;
for (int i=len+1;i>=1;i--) if (next[i]==1) {//from the next[i]==1 to the back of the case k=i-1;
Break
} int ans=len;//to judge the situation out of the while (Next[ans+1]-1>=k) ans=next[ans+1]-1;
printf ("%d", ans);
return 0; }