Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,844 questions

55,671 answers

573 users

How to check whether each substring range (L to R) from an array of substring ranges is a palindrome in Pascal

1 Answer

0 votes
program PalindromeCheck;

const
  Rows = 3;

type
  RangeArray = array[1..Rows, 1..2] of Integer;

function IsPalindrome(const S: string; Left, Right: Integer): Boolean;
begin
  while Left < Right do
  begin
    if S[Left] <> S[Right] then
    begin
      IsPalindrome := False;
      Exit;
    end;
    Inc(Left);
    Dec(Right);
  end;
  IsPalindrome := True;
end;

procedure CheckRangesForPalindrome(const S: string; const Ranges: RangeArray);
var
  I, StartIdx, EndIdx: Integer;
  SubStr: string;
begin
  for I := 1 to Rows do
  begin
    StartIdx := Ranges[I, 1] + 1;  
    EndIdx := Ranges[I, 2] + 1;
    SubStr := Copy(S, StartIdx, EndIdx - StartIdx + 1);

    Write(SubStr, ': ');
    if IsPalindrome(S, StartIdx, EndIdx) then
      WriteLn('Palindrome')
    else
      WriteLn('Not palindrome');
  end;
end;

var
  Str: string;
  Ranges: RangeArray;

begin
  Str := 'abcddcbeebc';
  Ranges[1, 1] := 2; Ranges[1, 2] := 5;
  Ranges[2, 1] := 5; Ranges[2, 2] := 10;
  Ranges[3, 1] := 3; Ranges[3, 2] := 7;

  CheckRangesForPalindrome(Str, Ranges);
end.



(*
run:

cddc: Palindrome
cbeebc: Palindrome
ddcbe: Not palindrome

*)

 



answered Nov 16, 2025 by avibootz

Related questions

...