Cod sursa(job #144195)

Utilizator free2infiltrateNezbeda Harald free2infiltrate Data 27 februarie 2008 12:22:55
Problema Potrivirea sirurilor Scor 40
Compilator fpc Status done
Runda Arhiva educationala Marime 0.91 kb
program strmatch;
type str = array [1..2000000] of string[1];
var A,B : str;
    C : array [1..2000000] of longint;
    m,n,i,j,s : longint;
    f : text;
    ok : boolean;
begin
assign(f,'strmatch.in');
reset(f);
n := 0;
while not eoln(f) do begin
inc(n);
read(f,A[n]);
end;
readln(f);
m := 0;
while not eoln(f) do begin
inc(m);
read(f,B[m]);
end;
close(f);
s := 0;
for i := 1 to m do
if B[i]=A[1] then begin
             ok := true;
             for j := 1 to n-1 do
             if B[i+j]<>A[1+j] then begin
                                    ok := false;
                                    break;
                                    end;
             if ok then begin
                        inc(s);
                        C[s] := i;
                        end;
             end;
assign(f,'strmatch.out');
rewrite(f);
writeln(f,s);
for i := 1 to s do
write(f,C[i]-1,' ');
close(f);
end.