.
..
exo01.adb (download) (view)
exo02.adb (download) (view)
exo04.adb (download) (view)
src.pdf (download)

--------------------------------------------------------------------------------
--  *  Prog name exo04.adb
--  *  Project name td_01_03
--  *
--  *  Version 1.0
--  *  Last update 11/09/08
--  *
--  *  Created by Pierre-FranÂois LÂŽon on 11/09/08.
--  *  Copyright (c) 2008 __MyCompanyName__.
--  *  All rights reserved.
--  *    or (keep only one line or write your own)
--  *  GNAT modified GNU General Public License
--  *
--------------------------------------------------------------------------------
with Ada.Text_IO, ada.integer_text_io;
with Ada.Numerics.Discrete_Random;
use  Ada.Text_IO, ada.integer_text_io;

procedure Exo04 is
   procedure Put(B : Boolean) is
   begin
      Put(Boolean'Image(B));
   end Put;

   function Contient_Pos_I(Grande, Petite : in String; Pos : in Integer) return Boolean is
   begin
      for I in Petite'Range loop
         if Petite(I) /= Grande(Pos + I - 1) then
            return False;
         end if;
      end loop;

      return True;
   end Contient_Pos_I;

   function Contient(Grande, Petite : String) return Natural is
   begin
      for I in Grande'First..(Grande'Last - Petite'Length + 1) loop
         if Contient_Pos_I(Grande, Petite, I) then
            return I;
         end if;
      end loop;

      return 0;
   end Contient;

begin
   Put("Contient_Pos_I(""abaabbab"", ""abb"", 1) = "); Put(Contient_Pos_I("abaabbab", "abb", 1)); New_Line;
   Put("Contient_Pos_I(""abaabbab"", ""abb"", 2) = "); Put(Contient_Pos_I("abaabbab", "abb", 2)); New_Line;
   Put("Contient_Pos_I(""abaabbab"", ""abb"", 3) = "); Put(Contient_Pos_I("abaabbab", "abb", 3)); New_Line;
   Put("Contient_Pos_I(""abaabbab"", ""abb"", 4) = "); Put(Contient_Pos_I("abaabbab", "abb", 4)); New_Line;
   Put("Contient_Pos_I(""abaabbab"", ""abb"", 5) = "); Put(Contient_Pos_I("abaabbab", "abb", 5)); New_Line;

   Put("Contient(""abaabbab"", ""abb"")  = "); Put(Contient("abaabbab", "abb"), 1); New_Line;
   Put("Contient(""abaabbab"", ""abc"")  = "); Put(Contient("abaabbab", "abc"), 1); New_Line;

   Put("Contient(""abaabbabc"", ""abc"") = "); Put(Contient("abaabbabc", "abc"), 1); New_Line;
end Exo04;
--  Contient_Pos_I("abaabbab", "abb", 1) = FALSE
--  Contient_Pos_I("abaabbab", "abb", 2) = FALSE
--  Contient_Pos_I("abaabbab", "abb", 3) = FALSE
--  Contient_Pos_I("abaabbab", "abb", 4) = TRUE
--  Contient_Pos_I("abaabbab", "abb", 5) = FALSE
--  Contient("abaabbab", "abb")  = 4
--  Contient("abaabbab", "abc")  = 0
--  Contient("abaabbabc", "abc") = 7
 
Webmaster : pierrefrancois.leon@laposte.net

Valid XHTML 1.0 Strict Valid CSS!