| Palindromy |
|
program palindromy;
function PalindromIter (S : String) : Boolean; { Funkcja sprawdza iteracyjnie, czy slowo jest palindromem. } var  Jest : Boolean;  I : Byte; begin  Jest := True; I := 1;  while (Jest and (I<=(Length(S) div 2))) do  begin    if (S[I]<>S[Length(S)-I+1]) then      Jest := False;    Inc (I)  end;  PalindromIter := Jest; end; function PalindromReku (S : String) : Boolean; { Funkcja sprawdza rekurencyjnie, czy slowo jest palindromem. } begin  if (Length(S)<=1) then    PalindromReku := True  else    if (S[1] = S[Length(S)]) then      PalindromReku := PalindromReku(Copy (S, 2, Length(S)-2))    else      PalindromReku := False end; var  Slowo : String; begin  repeat    write ('Podaj slowo (Enter, aby zakonczyc): '); readln (Slowo);    if (Slowo<>'') then    begin      writeln ('Wynik rekurencyjny: ', PalindromReku (Slowo));      writeln ('Wynik iteracyjny: ', PalindromIter (Slowo));      writeln;    end;  until (Slowo='') end. |
;



