Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with entrees_sorties; use entrees_sorties;
- procedure tp7_3 is
- function minuscule(ch : Character) return Character is
- begin
- if(Character'pos(ch) >= 65 AND Character'pos(ch) <= 90) then
- return Character'val(Character'pos(ch) + 26 + 6);
- else
- return ch;
- end if;
- end minuscule;
- NB_MAX : constant Integer := 50;
- BORNE_INF : constant Integer := 1;
- BORNE_SUP : constant Integer := BORNE_INF + NB_MAX - 1;
- subtype Intervalle is Integer range BORNE_INF..BORNE_SUP;
- type TabChaine is array(Intervalle) of Character;
- laChaine : TabChaine;
- nbLettres : Integer;
- indice : Integer;
- lettre : Character;
- finSaisie : Boolean;
- finGlobale : Boolean;
- i, j : Integer;
- estPalindrome : Boolean;
- begin
- finGlobale := FALSE;
- while(not(finGlobale)) loop
- put("Saisissez la chaine a tester et terminez par [$] : ");
- finSaisie := FALSE;
- indice := BORNE_INF;
- nbLettres := 0;
- while(not(finSaisie) AND nbLettres < NB_MAX) loop
- get(lettre);
- if(lettre = '$') then
- finSaisie := TRUE;
- else
- laChaine(indice) := lettre;
- indice := indice + 1;
- nbLettres := nbLettres + 1;
- end if;
- end loop;
- if(nbLettres > 0) then
- i := BORNE_INF;
- j := BORNE_INF + nbLettres - 1;
- estPalindrome := TRUE;
- while(i < (BORNE_INF + nbLettres/2) AND j >= (BORNE_INF + nbLettres/2)) loop
- while(laChaine(i) = ' ') loop
- i := i+1;
- end loop;
- while(laChaine(j) = ' ') loop
- j := j-1;
- end loop;
- if(minuscule(laChaine(i)) /= minuscule(laChaine(j))) then
- estPalindrome := FALSE;
- end if;
- i := i+1;
- j := j-1;
- end loop;
- put('[');
- for a in BORNE_INF..(BORNE_INF+nbLettres-1) loop
- put(laChaine(a));
- end loop;
- put(']');
- if(estPalindrome) then
- put(" est un palindrome");
- else
- put(" n'est pas un palindrome");
- end if;
- new_line;
- else
- finGlobale := TRUE;
- end if;
- end loop;
- end tp7_3;
Advertisement
Add Comment
Please, Sign In to add comment