Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with Ada.Text_IO;
- use Ada.Text_IO;
- procedure Main is
- type Index is new Integer;
- type Elem is new Integer;
- type Mátrix is array (Index range <>, Index range <>) of Elem;
- procedure spiralRead( M : in out Mátrix ) is
- type Irány is (Jobb,Bal,Fel,Le);
- LAYER : Index := 1;
- DIR : Irány := Bal;
- I : Index := M'First(1);
- J : Index := M'First(2);
- IND : Index := 1;
- INDMAX : Index := M'Length(1) * M'Length(2);
- begin
- <<BEJAR>>
- case DIR is
- when Bal =>
- begin
- for X in 1..(LAYER - 1) loop
- I := Index'Succ(I);
- end loop;
- J := M'First(2) + (LAYER - 1);
- for X in LAYER..(M'Length(2) - LAYER) loop
- Put_Line(Elem'Image(M(I,J)));
- J := Index'Succ(J);
- IND := Index'Succ(IND);
- if IND > INDMAX then goto KILEP; end if;
- end loop;
- DIR := Le;
- end;
- when Jobb =>
- begin
- J := M'Last(2) - (LAYER - 1);
- for X in LAYER..(M'Length(2) - LAYER) loop
- Put_Line(Elem'Image(M(I,J)));
- J := Index'Pred(J);
- IND := Index'Succ(IND);
- if IND > INDMAX then goto KILEP; end if;
- end loop;
- DIR := Fel;
- end;
- when Fel =>
- begin
- I := M'Last(1) - (LAYER - 1);
- for X in LAYER..(M'Length(1) - LAYER) loop
- Put_Line(Elem'Image(M(I,J)));
- I := Index'Pred(I);
- IND := Index'Succ(IND);
- if IND > INDMAX then goto KILEP; end if;
- end loop;
- DIR := Bal;
- LAYER := Index'Succ(LAYER);
- end;
- when Le =>
- begin
- I := M'First(1) + (LAYER - 1);
- for X in LAYER..(M'Length(1) - LAYER) loop
- Put_Line(Elem'Image(M(I,J)));
- I := Index'Succ(I);
- IND := Index'Succ(IND);
- if IND > INDMAX then goto KILEP; end if;
- end loop;
- DIR := Jobb;
- end;
- end case;
- if IND <= INDMAX then goto BEJAR; end if;
- <<KILEP>>
- end spiralRead;
- M0 : Mátrix := ( (1,2) , (4,3) );
- M1 : Mátrix := ( (1,2,3,4,5) , (12,13,14,15,6) , (11,10,9,8,7));
- 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));
- begin
- spiralRead(M2);
- end Main;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement