Advertisement
Guest User

Untitled

a guest
Sep 30th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 2.62 KB | None | 0 0
  1. with Ada.Text_IO;
  2. use Ada.Text_IO;
  3.  
  4. procedure Main is
  5.  
  6.    type Index is new Integer;
  7.    type Elem is new Integer;
  8.    type Mátrix is array (Index range <>, Index range <>) of Elem;
  9.  
  10.    procedure spiralRead( M : in out Mátrix ) is
  11.       type Irány is (Jobb,Bal,Fel,Le);
  12.       LAYER : Index := 1;
  13.       DIR : Irány := Bal;
  14.       I : Index := M'First(1);
  15.       J : Index := M'First(2);
  16.       IND : Index := 1;
  17.       INDMAX : Index := M'Length(1) * M'Length(2);
  18.    begin
  19.  
  20.       <<BEJAR>>
  21.       case DIR is
  22.          when Bal =>
  23.             begin
  24.                for X in 1..(LAYER - 1) loop
  25.                   I := Index'Succ(I);
  26.                end loop;
  27.                J := M'First(2) + (LAYER - 1);
  28.                for X in LAYER..(M'Length(2) - LAYER) loop
  29.                   Put_Line(Elem'Image(M(I,J)));
  30.                   J := Index'Succ(J);
  31.                   IND := Index'Succ(IND);
  32.                   if IND > INDMAX then goto KILEP; end if;
  33.                end loop;
  34.                DIR := Le;
  35.             end;
  36.          when Jobb =>
  37.             begin
  38.                J := M'Last(2) - (LAYER - 1);
  39.                for X in LAYER..(M'Length(2) - LAYER) loop
  40.                   Put_Line(Elem'Image(M(I,J)));
  41.                   J := Index'Pred(J);
  42.                   IND := Index'Succ(IND);
  43.                   if IND > INDMAX then goto KILEP; end if;
  44.                end loop;
  45.                DIR := Fel;
  46.             end;
  47.          when Fel =>
  48.             begin
  49.                I := M'Last(1) - (LAYER - 1);
  50.                for X in LAYER..(M'Length(1) - LAYER) loop
  51.                   Put_Line(Elem'Image(M(I,J)));
  52.                   I := Index'Pred(I);
  53.                   IND := Index'Succ(IND);
  54.                   if IND > INDMAX then goto KILEP; end if;
  55.                end loop;
  56.                DIR := Bal;
  57.                LAYER := Index'Succ(LAYER);
  58.             end;
  59.          when Le =>
  60.             begin
  61.                I := M'First(1) + (LAYER - 1);
  62.                for X in LAYER..(M'Length(1) - LAYER) loop
  63.                   Put_Line(Elem'Image(M(I,J)));
  64.                   I := Index'Succ(I);
  65.                   IND := Index'Succ(IND);
  66.                   if IND > INDMAX then goto KILEP; end if;
  67.                end loop;
  68.                DIR := Jobb;
  69.             end;
  70.       end case;
  71.       if IND <= INDMAX then goto BEJAR; end if;
  72.       <<KILEP>>
  73.  
  74.    end spiralRead;
  75.  
  76.    M0 : Mátrix := ( (1,2) , (4,3) );
  77.    M1 : Mátrix := ( (1,2,3,4,5) , (12,13,14,15,6) , (11,10,9,8,7));
  78.    M2 : Mátrix := ( (1,2,3,4,5,6) , (16,17,18,19,20,7) , (15,24,23,22,21,8) , (14,13,12,11,10,9));
  79.  
  80. begin
  81.    spiralRead(M2);
  82.  
  83.  
  84. end Main;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement