Pagini recente » Cod sursa (job #1759602) | Cod sursa (job #1216579) | Cod sursa (job #956102) | Cod sursa (job #1875639) | Cod sursa (job #2518680)
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int SMAX = 1000005;
char s[SMAX];
int z[SMAX];
int main(){
freopen("prefix.in","r",stdin);
freopen("prefix.out","w",stdout);
int tests;
scanf("%d\n",&tests);
for(;tests;tests--){
scanf("%s",&s);
int l=strlen(s);
int st=0,dr=0;
for(int k=1;k<l;++k){
if(k>dr){
st=dr=k;
while(dr<l && s[dr]==s[dr-st])
++dr;
z[k]=dr-st;
dr--;
}else{
int k1=k-st;
if(z[k1]<dr-k+1)
z[k]=z[k1];
else{
st=k;
while(dr<l && s[dr]==s[dr-st])
++dr;
z[k]=dr-st;
dr--;
}
}
}
int maxs=0;
for(int i=1;i<l;++i)
if(z[i]>=i)
maxs=max(maxs,i+z[i]/i*i);
/*
for(int i=0;i<l;++i)
printf("%c ",s[i]);
printf("\n");
for(int i=0;i<l;++i)
printf("%d ",z[i]);
printf("\n");
*/
printf("%d\n",maxs);
}
return 0;
}