All pastes #805776 Raw Edit

Jemand

public text v1 · immutable
·published 2007-12-04 17:34 UTC
rendered paste body
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Command_Line;
use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Command_Line;


procedure code is
   Eingabe        : Integer;
   Zahl1          : Integer;
   Zahl2          : Integer;
   Codierte_Zahl  : Integer;

   Zahl           : Integer;
   A              : Integer := 0;
   B              : Integer := 0;



   procedure Decode (Eingabe : Integer) is

   begin
      Get (Zahl);
      while Zahl mod 2 = 0 loop
         Zahl := Zahl / 2;
         A := A + 1;
      end loop;

      while  Zahl mod 3 = 0 loop
         B := B + 1;
         Zahl := Zahl / 3;
      end loop;
   end Decode;

   procedure Encode (Zahl1 : Integer; Zahl2 : Integer) is

   begin
      Codierte_Zahl := 2**Zahl1 * 3**Zahl2;
   end Encode;


begin
   if Ada.Command_Line.Argument_Count = 0 or
      Ada.Command_Line.Argument_Count > 2 then
      Put ("Bitte Kodierung oder zu kodierendes Zahlenpaar uebergeben!");
   else
      if Ada.Command_Line.Argument_Count = 1 then
         Get (Zahl);
         Decode (Zahl);
         if Zahl > 1 then
            Put ("Ungueltige Kodierung!");
         else
            Put (A);
            New_Line;
            Put (B);
         end if;

      else
         Get (Zahl1);
         Get (Zahl2);
         Encode (Zahl1, Zahl2);
         Put (Codierte_Zahl);
      end if;
   end if;
end code;