richie3366

tp7 palindrome (fini) ada

Nov 13th, 2012
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 2.13 KB | None | 0 0
  1. with entrees_sorties; use entrees_sorties;
  2.  
  3. procedure tp7_3 is
  4.  
  5.   function minuscule(ch : Character) return Character is
  6.   begin
  7.    
  8.     if(Character'pos(ch) >= 65 AND Character'pos(ch) <= 90) then
  9.      
  10.       return Character'val(Character'pos(ch) + 26 + 6);
  11.      
  12.     else
  13.       return ch;
  14.     end if;
  15.    
  16.   end minuscule;
  17.  
  18.  
  19.   NB_MAX : constant Integer := 50;
  20.   BORNE_INF : constant Integer := 1;
  21.   BORNE_SUP : constant Integer := BORNE_INF + NB_MAX - 1;
  22.  
  23.   subtype Intervalle is Integer range BORNE_INF..BORNE_SUP;
  24.   type TabChaine is array(Intervalle) of Character;
  25.  
  26.   laChaine : TabChaine;
  27.  
  28.   nbLettres : Integer;
  29.   indice : Integer;
  30.   lettre : Character;
  31.  
  32.   finSaisie : Boolean;
  33.   finGlobale : Boolean;
  34.  
  35.   i, j : Integer;
  36.   estPalindrome : Boolean;
  37.  
  38. begin
  39.  
  40.   finGlobale := FALSE;
  41.  
  42.   while(not(finGlobale)) loop
  43.    
  44.     put("Saisissez la chaine a tester et terminez par [$] : ");
  45.    
  46.     finSaisie := FALSE;
  47.     indice := BORNE_INF;
  48.     nbLettres := 0;
  49.    
  50.     while(not(finSaisie) AND nbLettres < NB_MAX) loop
  51.      
  52.       get(lettre);
  53.      
  54.       if(lettre = '$') then
  55.     finSaisie := TRUE;
  56.       else
  57.     laChaine(indice) := lettre;
  58.     indice := indice + 1;
  59.     nbLettres := nbLettres + 1;
  60.       end if;
  61.      
  62.     end loop;
  63.    
  64.     if(nbLettres > 0) then
  65.      
  66.       i := BORNE_INF;
  67.       j := BORNE_INF + nbLettres - 1;
  68.      
  69.       estPalindrome := TRUE;
  70.      
  71.       while(i < (BORNE_INF + nbLettres/2) AND j >= (BORNE_INF + nbLettres/2)) loop
  72.    
  73.     while(laChaine(i) = ' ') loop
  74.       i := i+1;
  75.     end loop;
  76.    
  77.     while(laChaine(j) = ' ') loop
  78.       j := j-1;
  79.     end loop;
  80.    
  81.     if(minuscule(laChaine(i)) /= minuscule(laChaine(j))) then
  82.       estPalindrome := FALSE;
  83.     end if;
  84.    
  85.     i := i+1;
  86.     j := j-1;
  87.       end loop;
  88.      
  89.       put('[');
  90.       for a in BORNE_INF..(BORNE_INF+nbLettres-1) loop
  91.     put(laChaine(a));
  92.       end loop;
  93.       put(']');
  94.      
  95.       if(estPalindrome) then
  96.     put(" est un palindrome");
  97.       else
  98.     put(" n'est pas un palindrome");
  99.       end if;
  100.       new_line;
  101.     else
  102.       finGlobale := TRUE;
  103.     end if;
  104.      
  105.   end loop;
  106.  
  107. end tp7_3;
Advertisement
Add Comment
Please, Sign In to add comment