Mai intai trebuie sa te autentifici.
Cod sursa(job #329372)
| Utilizator | Data | 5 iulie 2009 23:25:32 | |
|---|---|---|---|
| Problema | Prefix | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.64 kb |
#include <stdio.h>
#include <string.h>
#define max 1000002
char P[max];
int n, pi[max], t,q, k,rez;
int main()
{
freopen("prefix.in", "r", stdin);
freopen("prefix.out", "w", stdout);
scanf("%d\n", &t);
for (; t; t--)
{
scanf("%s\n", P+1);
n=strlen(P+1);
pi[1]=0;k=0;
for (q=2; q<=n; q++)
{
while (k && P[k+1]!=P[q]) k=pi[k];
if (P[k+1]==P[q]) k++;
pi[q]=k;
if (k && (q%(q-k))==0) rez=q;
}
printf("%d\n",rez);
}
return 0;
} 