Pagini recente » Cod sursa (job #2617155) | Monitorul de evaluare | Istoria paginii runda/coci-finala-2013/clasament | Cod sursa (job #444932) | Cod sursa (job #1599546)
program potisir;
type
arch=array[1..2000005] of char;
sir1=array[1..2000005] of longint;
var
a,b:arch;
f:text;
q,i,n,m,m1:longint;
pi,pos:sir1;
begin
m:=0;
m1:=0;
assign(f,'strmatch.in');
reset(f);
while (not(eoln(f))) do
begin
m:=m+1;
read(f,a[m]);
end;
readln(f);
while (not(eof(f)))
do begin
inc(m1);
read(f,b[m1]);
end;
q:=0;
n:=0;
pi[1]:=0;
for i:=2 to m do
begin
while ((q>0) and (a[q+1]<>a[i])) do
begin
q:=pi[q];
end;
if (a[q+1]=a[i]) then inc(q);
pi[i]:=q;
end;
q:=0;
for i:=1 to m1 do
begin
while ((q>0) and (a[q+1]<>b[i]))
do
begin
q:=pi[q];
end;
if ( a[q+1]=b[i]) then q:=q+1;
if (q=m) then
begin
q:=pi[m];
n:=n+1;
if (n<=1000) then pos[n]:=i-m;
end;
end;
close(f);
assign(f,'strmatch.out');
rewrite(f);
writeln(f,n);
if n>1000 then n:=1000;
for i:=1 to n do write(f,pos[i],' ');
close(f);
end.