Pagini recente » Cod sursa (job #1271681) | Cod sursa (job #773882) | Cod sursa (job #721724) | Cod sursa (job #720426) | Cod sursa (job #872164)
Cod sursa(job #872164)
Program p1;
var fi,fo:text; i,k,n,m,nrsol:longint;
a,b:array[0..2000001] of char; r:set of char;
p:array[0..2000001] of longint;
sol:array[0..1001] of longint;
begin
assign(fi,'strmatch.in'); reset(fi);
assign(fo,'strmatch.out'); rewrite(fo);
readln(fi,a); read(fi,b); nrsol:=0;
p[1]:=0; k:=0; m:=1; n:=1; r:=['A'..'Z']+['a'..'z']+['0'..'9'];
while a[m] in r do m:=m+1;
while b[n] in r do n:=n+1;
m:=m-1; n:=n-1;
for i:=2 to m do begin
while (k>0) and (a[k+1]<>a[i]) do k:=p[k];
if a[k+1]=a[i] then k:=k+1;
p[i]:=k;
end;
k:=0;
for i:=1 to n do begin
while (k>0) and (a[k+1]<>b[i]) do k:=p[k];
if a[k+1]=b[i] then k:=k+1;
if k=m then begin
k:=p[m];
nrsol:=nrsol+1;
if nrsol<=1000 then sol[nrsol]:=i-m;
end;
end;
writeln(fo,nrsol);
if nrsol>1000 then nrsol:=1000;
for i:=1 to nrsol do write(fo,sol[i],' ');
close(fi); close(fo);
end.