Cod sursa(job #857599)
| Utilizator | Data | 18 ianuarie 2013 00:14:09 | |
|---|---|---|---|
| Problema | Prefix | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.51 kb |
#include<cstdio>
#include<cstring>
char s[1000005];
int p[1000005];
int main (void)
{
freopen ("prefix.in","r",stdin);
#ifdef INFOARENA
freopen ("prefix.out","w",stdout);
#endif
int t,n;
scanf ("%d ",&t);
while(t--){
gets (s+1);
n=strlen (s+1);
p[1]=0;
int x=0;
for(int i=2;i<=n;i++){
while(x>0&&s[x+1]!=s[i])
x=p[x];
if(s[x+1]==s[i])
x++;
p[i]=x;
}
for(int i=n;i>=1;i--)
if(p[i]&&i%(i-p[i])==0){
printf ("%d\n",i);
goto END;
}
puts ("0");
END:;
}
return 0;
}
