Sign in Join
Wiki copytemporary

Palindrome/fr

Deutsch · English · Français · Suomi

Palindrome

Un palindrome est un mot, une phrase, un nombre ou une autre séquence de symboles ou d'éléments, dont le sens peut être interprété de la même manière dans les deux sens de lecture.

Exemples

Anglais

Arabe

Arménien

Finnois

Russe

Français

Fonction IsPalindome

Cette fonction convient à la fois pour les encodages ASCII et UTF-8.

pascal
function IsPalindome(const a_text: string): boolean;
var
  i, j       :longint;
  s1, s2, s3 :string;
begin
  s1 := UTF8LowerCase( a_text );
  j := length( s1 );
  i := 1;
  s2 := '';
  s3 := '';
  while ( i <= j ) do
    begin
      if s1[i] < #$C0 then  // ASCII
        begin
          if (s1[i] >= #$30) and (s1[i] < #$7B)then
            begin
              if (s1[i] > #$60) or (s1[i] < #$3A) then
                begin
                  s2 := s1[i] + s2;
                  s3 := s3 + s1[i];
                end;
              end;
            inc( i );
          end
        else
        begin
          begin
            if s1[i] < #$E0 then  // two byte
              begin
                if ((s1[i] > #$C2) and ( not
                  // Armenian punctuation
                  ((s1[i] = #$D5) and ((s1[i+1] >= #$99) and (s1[i+1] < #$A0)))
                  )) then
                  begin
                    s2 := s1[i]+ s1[i+1] + s2;
                    s3 := s3 + s1[i] + s1[i+1];
                  end;
                inc( i ,2);
              end
            else
              begin
                if s1[i] < #$F0 then  // three byte
                  begin
                    if not (
                      // General punctuation
                      (s1[i] = #$E2) and ((s1[i+1]= #$80)
                      or ((s1[i+1]= #$81) and (s1[i+2]< #$B0)))
                      ) then
                      begin
                        s2 := s1[i]+ s1[i+1] + s1[i+2]+ s2;
                        s3 := s3 + s1[i] + s1[i+1] + s1[i+2];
                      end;
                    inc( i ,3);
                  end
                else
                  begin
                    s2 := s1[i]+ s1[i+1] + s1[i+2]+ s1[i+3] + s2;
                    s3 := s3 + s1[i] + s1[i+1] + s1[i+2] + s1[i+3];
                    inc( i ,4);
                  end
              end;
          end;
        end;
    end;
  if s2 <> '' then result := s2=s3 else result := false;
end;

From the Free Pascal wiki, page "Palindrome/fr", as it stood on 2020-02-23 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 2, last changed by WikiArchive .

Edited on wiki.freepascal.org by 3 people, 2014–2020

From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.

WhenWhoWhat changed
E-ricCreated page
E-ric
FTurtle
TrevFixed syntax highlighting; removed categories included in template (minor)

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.