Pagini recente » Cod sursa (job #789651) | Cod sursa (job #266234) | Cod sursa (job #600443) | Cod sursa (job #1209440) | Cod sursa (job #175777)
Cod sursa(job #175777)
program prefix_;
var t:integer;
w,max,j,i,n,k,q:longint;
v:array[1..200] of char;
ok:boolean;
vv:array[1..200] of integer;
procedure prefix;
begin
k:=0; vv[1]:=0;
for q:=2 to n do
begin
while (k>0)and(v[k+1]<>v[q]) do k:=vv[k];
if v[k+1]=v[q] then k:=k+1;
vv[q]:=k;
end;
end;
begin
assign(input,'prefix.in'); reset(input);
assign(output,'prefix.out'); rewrite(output);
readln(t);
for w:=1 to t do
begin
n:=0;
while not seekeoln do begin inc(n); read(v[n]); end;
prefix;
max:=0;
for i:=1 to n do
begin
if vv[i]<>0 then
if (i div vv[i]=2)and(i mod vv[i]=0) then
begin
j:=i; ok:=true;
while (ok)and(j<=n) do
begin
if (vv[j] mod vv[i]<>0)or(vv[j]=0) then ok:=false;
j:=j+vv[i];
end;
if not ok then j:=j-2*vv[i]
else j:=j-vv[i];
if j>max then max:=j;
end;
end;
writeln(max);
readln;
end;
close(input);
close(output);
end.