program LongestPalindrome;
function IsPalindrome(const s: string; i, j: Integer): Boolean;
var
k: Integer;
begin
for k := 0 to (j - i) div 2 do
if s[i + k] <> s[j - k] then
begin
IsPalindrome := False;
Exit;
end;
IsPalindrome := True;
end;
function LongestPalindromeSubstring(const s: string): Integer;
var
i, j, k, len, start, longestLength: Integer;
begin
len := Length(s);
longestLength := 1;
start := 1;
for i := 1 to len do
for j := i to len do
if IsPalindrome(s, i, j) and ((j - i + 1) > longestLength) then
begin
start := i;
longestLength := j - i + 1;
end;
Write('Longest palindrome substring = ');
for k := start to start + longestLength - 1 do
Write(s[k]);
Writeln;
LongestPalindromeSubstring := longestLength;
end;
var
input: string;
lengthFound: Integer;
begin
input := 'qabcbaproggorpxyyxzv';
lengthFound := LongestPalindromeSubstring(input);
Writeln('Length palindrome substring length = ', lengthFound);
end.
(*
run:
Longest palindrome substring = proggorp
Length palindrome substring length = 8
*)