pascal蛇形矩阵n*n的矩阵,n:1-20,样例输出:1 12 11 10 2 13 16 9 3
来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/08/19 13:33:39
pascal蛇形矩阵
n*n的矩阵,n:1-20,样例输出:1 12 11 10 2 13 16 9 3 14 15 8 4 5 6 7 每2个数之间1个空格
是个逆时针的蛇形
n*n的矩阵,n:1-20,样例输出:1 12 11 10 2 13 16 9 3 14 15 8 4 5 6 7 每2个数之间1个空格
是个逆时针的蛇形
![pascal蛇形矩阵n*n的矩阵,n:1-20,样例输出:1 12 11 10 2 13 16 9 3](/uploads/image/z/13490108-44-8.jpg?t=pascal%E8%9B%87%E5%BD%A2%E7%9F%A9%E9%98%B5n%EF%BC%8An%E7%9A%84%E7%9F%A9%E9%98%B5%2Cn%EF%BC%9A1%EF%BC%8D20%2C%E6%A0%B7%E4%BE%8B%E8%BE%93%E5%87%BA%EF%BC%9A1%E3%80%80%E3%80%80%E3%80%8012%E3%80%80%E3%80%8011%E3%80%8010+2%E3%80%80%E3%80%80%E3%80%8013%E3%80%80%E3%80%8016%E3%80%80%E3%80%809+3)
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.
请采纳
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.
请采纳