Mình thì làm trâu bò kiểu này ra cơ mà tốc độ với n lớn chắc ko cao
Code:
Uses crt;
Const MAX=100;
Type
mang=array[1..MAX] of integer;
Var
a: array[1..MAX,1..MAX] of integer;
temp,last : mang;
n,m,k: integer;
i,j,dem: integer;
Procedure Inra;
Var
i,j: integer;
Begin
For i:=1 to n do
Begin
For j:=1 to n do Write(a[i][j],' ');
Writeln;
End;
Writeln;
End;
Procedure GanHang(var t:mang; v: integer);
Var i: integer;
Begin
For i:=1 to n do t[i]:=a[v][i];
End;
Procedure GanCot(var t:mang; v: integer);
Var i: integer;
Begin
For i:=1 to n do t[i]:=a[i][v];
End;
Procedure DoiHang(x: integer);
Var
j,y: integer;
Begin
If x=1 then y:=n
Else y:=x-1;
GanHang(temp, x);
For j:=1 to n do
a[y][j]:=temp[j];
End;
Procedure DoiCot(x: integer);
Var
i,y: integer;
Begin
If x=1 then y:=n
Else y:=x-1;
GanCot(temp, x);
For i:=1 to n do
a[i][y]:=temp[i];
End;
BEGIN
Clrscr;
// Write('Nhap n, m ,k: '); Readln(n,m,k);
n:=10; m:=6; k:=7; dem:=0;
For i:=1 to n do
For j:=1 to n do
Begin
dem+=1;
a[i][j]:=dem;
End;
Inra;
Writeln('k = ',k);
For j:=1 to k do
Begin
GanHang(last,n);
For i:=1 to n-1 do DoiHang(i);
For i:=1 to n do a[n-1][i]:=last[i];
End;
Inra;
Writeln('m = ',m);
For i:=1 to m do
Begin
GanCot(last,n);
For j:=1 to n-1 do DoiCot(j);
For j:=1 to n do a[j][n-1]:=last[j];
End;
Inra;
END.
Bookmarks