Advertisement
dxvmxnd

Untitled

Mar 13th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. function IsPalindrome(Arr: Array Of Integer; left, right : Integer) : Boolean;
  2. var
  3. IsCorrect : Boolean;
  4. begin
  5. if (left >= right) then
  6. IsCorrect := True
  7. else
  8. begin
  9. IsCorrect := (Arr[left] = Arr[right]) and IsPalindrome(Arr, left+1, right-1);
  10. end;
  11.  
  12. IsPalindrome := IsCorrect;
  13. end;
  14.  
  15. procedure FindPalindrome(Arr : Array Of Integer; var I, J : Integer);
  16. var
  17. IndexI, IndexJ : Integer;
  18. MaxI, MaxJ : Integer;
  19. begin
  20.  
  21. MaxI := 0;
  22. MaxJ := 0;
  23.  
  24. For IndexI := 0 To High(Arr) Do
  25. Begin
  26. For IndexJ := High(Arr) Downto IndexI Do
  27. Begin
  28. If IsPalindrome(Arr, IndexI, IndexJ) Then
  29. Begin
  30. If(IndexJ - IndexI) > (MaxJ - MaxI) Then
  31. Begin
  32. MaxI := IndexI;
  33. MaxJ := IndexJ;
  34. End;
  35. End;
  36. End;
  37. End;
  38.  
  39.  
  40. I := MaxI;
  41. J := MaxJ;
  42. end;
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement