Skip to content

Instantly share code, notes, and snippets.

@ludo237
Last active September 28, 2015 02:38
Show Gist options
  • Save ludo237/1371406 to your computer and use it in GitHub Desktop.
Save ludo237/1371406 to your computer and use it in GitHub Desktop.
Palindrome in ADA
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Characters.Handling, Ada.Strings, Ada.Strings.Maps, Ada.Strings.Fixed;
use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Characters.Handling;
procedure Palindromi is
Scelta : Integer := 0 ;
procedure Intestazione is
begin
Put_Line("*** Controllo stringa palindroma ***") ;
Put_Line("*** Autore: Claudio Ludovico Panetta ***") ;
Put_Line("*** Data: 10/11/2011 ***") ;
Put_Line("*** Stato: Release 1.0.0.1 ***") ;
Put_Line("*** Eccezioni: Non Gestite ***") ;
New_Line(3) ;
end Intestazione ;
procedure Menu is
begin
New_Line(2) ;
Put_Line("*** Menu di scelta ***") ;
Put_Line("*** 1 - Controlla una stringa ***") ;
Put_Line("*** 2 - Esci dal programma ***") ;
Put_Line("*********************************") ;
New_Line(2) ;
end Menu ;
function CuraTesto(Stringa_Input: String) return String is
-- Ritorna tutto minuscolo
begin
return To_Lower(Stringa_Input) ;
end CuraTesto;
function InvertiStringa(Stringa_Input: String) return String is
-- Ritorna il reverse della stringa data
begin
-- Questo è per mostrare come avviene la ricorsione
Put_line(Item => Stringa_Input) ;
if Stringa_Input'Length <= 1 then
return Stringa_Input ;
else
return InvertiStringa(Stringa_Input(Stringa_Input'First + 1.. Stringa_Input'Last)) & Stringa_Input(Stringa_Input'First);
end if;
end InvertiStringa;
procedure Procedi(Scelta: in INTEGER) is
Input : String(1 .. 80); -- Input per ottenre la stringa dall'utente
Last : Natural; -- Il carattere finale
Reverse_input : String(1 .. 80); -- La stringa in reverse
begin
case(Scelta) is
when 1 =>
Put(Item => "Ciao, Inserisci una stringa di 80 o meno caratteri: ");
Get_Line(Item => Input, Last => Last);
Input := CuraTesto(Input) ;
Reverse_input(1..Last) := InvertiStringa(Input(1..Last));
Put("L'inverso e "); Put(Item => Reverse_input(1..Last));
New_Line(1) ;
if Reverse_input (1..Last) = Input (1..Last) THEN
Put(Item => "Ed e palindroma :D.");
New_Line(1);
else
Put(Item => "E non e palindroma :(.");
New_Line(1) ;
end if;
when 2 => Put_Line("Ciao Ciao") ;
when others => Put_Line("Non computato") ;
end case ;
end Procedi;
begin
Intestazione ;
while Scelta /= 2 Loop
Menu ;
Put("Fai la tua Scelta: ") ;
Get(Item => Scelta, Width => 0) ;
Skip_Line;
if(Scelta /=1 and Scelta /=2) then
Put_Line("Questa scelta non e' valida") ;
else
Procedi(Scelta) ;
end if ;
end loop ;
end Palindromi;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment