type pbyte=^byte; procedure RotateMatrix(pmatrix:pbyte; count:integer); pmatrix: ссылка на начало матрицы count: кол-во строк(столбцов) матрицыПример:
| Программа | Результат работы |
type pbyte=^byte; procedure RotateMatrix(pmatrix:pbyte; count:integer); begin // здесь - решение задачи end; const N=3; type matrix=array[1..N,1..N] of byte; var s:matrix= ( (1,2,3), (4,5,6), (7,8,9) ); procedure out(); // вывод матрицы на экран var i,j:integer; begin writeln; for i:=1 to N do begin for j:=1 to N do write(s[i,j]:5); writeln; end; end; begin out(); RotateMatrix(@s,N); out(); RotateMatrix(@s,N); out(); end. |
1 2 3
4 5 6
7 8 9
7 4 1
8 5 2
9 6 3
9 8 7
6 5 4
3 2 1
|
type pbyte=^byte;
ppbyte=^pbyte;
procedure RotateMatrixDynamic(pmatrix:ppbyte);
pmatrix: ссылка на начало матрицы (содержит адрес начала массива указателей на байтовые массивы)
Пример:
| Программа | Результат работы |
type pbyte=^byte;
ppbyte=^pbyte;
procedure RotateMatrixDynamic(pmatrix:ppbyte);
begin
// здесь - решение задачи
end;
Const N=3;
var ps:array of array of byte;
procedure fill(); // заполнение матрицы
var x:byte;
i,j:integer;
begin
x:=10;
setlength(ps,N);
for i:=0 to N-1 do begin
setLength(ps[i],N);
for j:=0 to N-1 do begin
ps[i][j]:=x;
inc(x,10);
end;
end;
end;
procedure out(); // вывод матрицы на экран
var i,j:integer;
begin
writeln;
for i:=0 to N-1 do begin
for j:=0 to N-1 do write(ps[i][j]:5);
writeln;
end;
end;
begin
fill();
out();
RotateMatrixDynamic(ppbyte(ps));
out();
RotateMatrixDynamic(ppbyte(ps));
out();
end.
|
10 20 30
40 50 60
70 80 90
70 40 10
80 50 20
90 60 30
90 80 70
60 50 40
30 20 10
|