samedi 10 septembre 2016
    1. Program long_palindrome;
    2. Var ch,ch1,max:string;
    3. i,j:integer;
    4. (*******************************************)
    5. Function palindrome(ch:string):boolean;
    6. Var i:integer; verif:boolean;
    7. Begin
    8. i:=0;
    9. Repeat
    10. i:=i+1;
    11. Verif := (ch[i] = ch[length(ch)-i+1]);
    12. Until (verif=false) or (i=length(ch) div 2);
    13. palindrome:=verif;
    14. End;
    15. (******************** P.P ***********************)
    16. Begin
    17. Writeln('Donner ch = ');
    18. Readln(ch); max:=ch[1];
    19. Repeat
    20. For j:=length(ch) downto 3 do
    21. Begin
    22. ch1:=copy(ch,1,j);
    23. If palindrome(ch1) and (length(ch1)>length(max)) Then max:=ch1;
    24. End;
    25. delete(ch,1,1);
    26. Until length(ch)=2;
    27. Writeln ('La plus longue chaine palindrome est : ', max)
    28. End.

0 commentaires:

Enregistrer un commentaire

Page Facebook

Turbo Pascal 32 bits

Turbo Pascal 64 bits