如下为规模为4的螺旋矩阵 1 12 11 10 2 13 16 9 3 14 15 8 4 5 6 7 求规模为n(n
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/15 17:59:28
如下为规模为4的螺旋矩阵 1 12 11 10 2 13 16 9 3 14 15 8 4 5 6 7 求规模为n(n
如下为规模为4的螺旋矩阵 1 12 11 10 2 13 16 9 3 14 15 8 4 5 6 7 求规模为n(n
如下为规模为4的螺旋矩阵 1 12 11 10 2 13 16 9 3 14 15 8 4 5 6 7 求规模为n(n
var i,j,k,sum,kk,n,y,x:longint;
a:array[1..21,1..21]of integer;
procedure work;
begin
k:=k+1;
inc(sum);
case kk mod 4 of
1:begin
y:=y+1;
a[y,x]:=sum;
end;
2:begin
x:=x+1;
a[y,x]:=sum;
end;
3:begin
y:=y-1;
a[y,x]:=sum;
end;
0:begin
x:=x-1;
a[y,x]:=sum;
end;
end;
end;
begin
assign(input,'backspin.in');
reset(input);
assign(output,'backspin.out');
rewrite(output);
kk:=0;
x:=1;
y:=0;
read(n);
i:=n+1;
while sumn*n do
begin
while i1 do
begin
j:=0;
i:=i-1;
if in then
while j2 do
begin
j:=j+1;
kk:=kk+1;
k:=0;
while ki do work;
end
else
begin
kk:=kk+1;
k:=0;
while ki do work;
end;
end;
end;
for i:=1 to n do
for j:=1 to n do
begin
if jn then write(a[i,j],' ')
else writeln(a[i,j]);
end;
close(input);
close(output);
end.
{我定的数据规模是n≤20}
自己列示好好算算,这题简直就是弱质题鐧惧害鍦板浘