Pagini recente » Cod sursa (job #557060) | Cod sursa (job #367988) | Cod sursa (job #1637535) | Cod sursa (job #277587) | Cod sursa (job #2593374)
#include <cstdio>
#include <cstring>
using namespace std;
const int NMAX = 1000000;
char s[NMAX + 5] , urm[NMAX + 5];
int main()
{
freopen("prefix.in" , "r" , stdin);
freopen("prefix.out" , "w" , stdout);
int t , n , i , j , k , lmax;
scanf("%d\n" , &t);
for(i = 1 ; i <= t ; i ++)
{
scanf("%s\n" , (s + 1));
n = strlen(s + 1);
urm[1] = k = lmax = 0;
for(j = 2 ; j <= n ; j ++)
{
while(k > 0 && s[k + 1] != s[j])
k = urm[k];
if(s[k + 1] == s[j])
k ++;
urm[j] = k;
if(s[k] == s[j] && k % (j - k) == 0)
lmax = j;
}
printf("%d\n" , lmax);
}
return 0;
}