igorich1376

Is_palindrome

Aug 24th, 2024 (edited)
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.92 KB | None | 0 0
  1. ##
  2. function is_palindrome(text: string): boolean;
  3. begin
  4.   var s := '';
  5.   text := text.ToLower;
  6.  
  7.   for var i := 1 to Length(text) do
  8.       if (text[i] <> ' ') and (text[i].isletter) then s := s + text[i];
  9.  
  10.   if (s[1:] = s[::-1]) then Result := true else Result := false;
  11. end;
  12. //
  13. var text := ReadString;
  14. Print(is_palindrome(text));
  15. ////// другой способ через replace ///////
  16. function is_palindrome(text: string): boolean;
  17. begin
  18.   text := text.ToLower;
  19.   text := text.Replace(',','');
  20.   text := text.replace ('.','');
  21.   text := text.replace ('!','');
  22.   text := text.replace ('?','');
  23.   text := text.replace ('-','');
  24.   text := text.replace (' ','');
  25.  
  26.     if (text = text[::-1]) then result := True
  27.         else result := False
  28. end;
  29.  
  30. println(is_palindrome('А роза упала на лапу Азора.'));
  31. println(is_palindrome('Gabler Ruby - burrel bag!'));
  32. print(is_palindrome('BEEGEEK'));
Advertisement
Add Comment
Please, Sign In to add comment