SHARE
TWEET

Untitled

a guest Oct 12th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program palindrome;
  2.  
  3. uses crt;
  4. var s : string;
  5. var max_subparlindrome : integer;
  6. var sub_parlindrome : string;
  7. function reverse(s : string) : string;
  8. var i,n : integer;
  9. var s_reverse : string;
  10. begin
  11.    n := length(s);
  12.    s_reverse := '';
  13.    for i:=n downto 1 do s_reverse := s_reverse + string(s[i]);
  14.    reverse :=s_reverse;
  15. end;
  16. function max_parlindrome(s : string) : integer;
  17. var i, n : integer;
  18. var substr : string;
  19. var max  : integer;
  20. begin
  21.    n := length(s);
  22.    max :=0;
  23.    for i:=1 to n do begin
  24.       substr := copy(s,1,i);
  25.       if substr = reverse(substr) then max:=i
  26.    end;
  27.    max_parlindrome:=max;
  28. end;
  29. BEGIN
  30.  clrscr;
  31.  write('s = '); readln(s);
  32.  while(length(s) > 0) do begin
  33.     max_subparlindrome := max_parlindrome(s);
  34.     sub_parlindrome:= copy(s,1,max_subparlindrome);
  35.     writeln(sub_parlindrome);
  36.     s:=copy(s,max_subparlindrome + 1,length(s));
  37.  end;
  38.  readln;
  39. END.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top