Book of tasks on programming. Old version

 

 by Aliaksandr N. Prykhodzka

 

publishing house, if, оператор ветвления, метод пузырьков, then, function, education, processor, array, транслятор, семинар, scolaire, procedure
 

Pascal. Answers. Pb.7. Realization of algorithms. Finding substring in string



главная страница


Pb.7.1


Program E_3_3_1;
uses crt, dos;
var
      AA, BB : string;
      K, L, S, I, J : integer;
begin
      AA:='abcd';
      BB:='aabdcadddcvabcdxyabcabcdw';
      K:=length(BB);
      L:=length(AA);
      I:=1;
      J:=1;
      S:=0;
      while (S=0) and (I<=K-L+1) do begin
            if BB[I+J-1]=AA[J] then J:=J+1
            else begin
                  I:=I+1;
                  J:=1
            end;
            if J>L then S:=I;
      end;
      writeln(S);
end.



Pb.7.2


Program E_3_3_4;
uses crt, dos;
var
      AA, BB : string;
      K, L, T, I, J : integer;
begin
      AA:='abcd';
      BB:='aabdcadddcvabcdxyabcabcdw';
      K:=length(BB);
      L:=length(AA);
      I:=1;
      J:=1;
      T:=0;
      while (I<=K-L+1) do begin
            if BB[I+J-1]=AA[J] then J:=J+1
            else begin
                  I:=I+1;
                  J:=1
            end;
            if J>L then begin
                  T:=T+1;
                  I:=I+1;
                  J:=1
            end;
      end;
      writeln(T);
end.

 

©   Aliaksandr Prykhodzka    1993 - 2007