Вводится строка. Найти слово — палиндром, имеющее самую большую длину — Pascal(Паскаль)

Палиндром — текст, читающийся одинаково слева направо и наоборот

uses
  crt;
const
  dividers=[' ',',','.',';',':','-','=','+'];
function Pa(s:string):boolean;
var
  i:integer;
  fl:boolean;
begin
  fl:=true;
  for i:=1 to length(s)div 2 do
    if s[i]<>s[length(s)-i+1] then
      fl:=false;
  Result:=fl
end;
var
  s,temp,max:string;
  i,ps:integer;
begin
  clrscr;
  writeln('Введите...');
  readln(s);
  temp:='';
  ps:=0;
  max:='';

  for i:=1 to length(s) do
  begin
    if not (s[i] in dividers) then
      temp:=temp+s[i];
    if ((s[i] in dividers) or (i=length(s))) and (temp<>'') then
    begin
      if Pa(temp) and (Length(temp)>Length(max)) then
      begin
        max:=temp;
        ps:=pos(temp,s)
      end;
      temp:='';
    end;
  end;
  if max<>'' then
    writeln('=: ',max,' =: ',ps)
  else
    writeln('Нет')
end.

Leave a Comment

61 − = 54