Pagini recente » Cod sursa (job #2675693) | Cod sursa (job #3174570) | Cod sursa (job #294130) | Cod sursa (job #563871) | Cod sursa (job #78821)
Cod sursa(job #78821)
program prefix;
const
fin='prefix.in';
fout='prefix.out';
type
sir=array[1..1000010] of char;
lsir=array[0..1000010] of longint;
var
t,i,j,n,k,q,l,x,y,it,best:longint;
f:text;
p:sir;
pi:lsir;
begin
assign(f,fin);assign(output,fout);
reset(f);rewrite(output);
readln(f,t);
for it:=1 to t do
begin
l:=1000000;
readln(f,p);
k:=0;
pi[1]:=0;
for q:=2 to l do
begin
while (k>0) and (p[k+1]<>p[q]) do
k:=pi[k];
if p[k+1]=p[q] then
inc(k);
pi[q]:=k;
if p[q]<'!' then
begin
l:=q-1;
break;
end;
end;
best:=0;
{for i:=l downto 2 do
if i-pi[i]<>0 then
begin
if (pi[i]<>0) then
if (i=(i div (i-pi[i]))*(i-pi[i])) then
begin
best:=i;
break;
end;
end;
writeln(best);}
end;
close(f);close(output);
end.