Cod sursa(job #100625)

Utilizator zappysBerghian Alexandru zappys Data 12 noiembrie 2007 15:19:58
Problema Abc2 Scor 0
Compilator fpc Status done
Runda Happy Coding 2007 Marime 2.01 kb
var   nr,ls,p:integer;
      c:array[1..10000000]of byte;
      s:array[1..21,1..50000]of byte;
      f,g:text;
      i,li,n,j,b:longint;
      y:string;
      ok:boolean;
      a:CHAR;
begin
assign(f,'abc2.in');
assign(g,'abc2.out');
reset(f);
rewrite(g);

        begin    {citire text}
        li:=1;

        while not(eoln(f))do begin
        read(f,a);
        if a='a' then c[li]:=1
                 else if a='b' then c[li]:=2
                                else c[li]:=3;
        inc(li);
        end;

        end;


        begin   {citire cuvinte}
        n:=li;

        li:=1;
        readln(f);
        readln(f,y);
        ls:=length(y);
        while not(eof(f))do begin
        ok:=true;

         {       for i:=1 to li-1 do
                if y=s[li,i] then begin ok:=false; break;end;}
        if ok= true then begin
                         p:=0;
                         for j:=1 to ls do begin
                         if y[j]='a' then s[li,j]:=1
                                        else if y[j]='b' then s[li,j]:=2
                                                        else s[li,j]:=3;
                         p:=s[li,j]+p;
                                        end;
                         s[li,ls+1]:=p;

                         end;
        inc(li);
        readln(f,y);

                                end;

        end;

        ls:=length(y);

        begin {partea grea}
        for i:=1 to li do begin

                for j:=1 to n-ls do begin

                        if s[i][1]=c[j]then begin
                        ok:=true;
                                for b:=2 to ls do begin
                                        if s[i,b]<>c[j+b-1] then begin ok:=false; break; end;

                                end;
                         if ok=true then inc(nr);
                        end;
                if ok then break;

                end;
            end;

        end;

writeln(g,nr-1);
close(f);
close(g);
end.