PASCAL蛇行方阵

来源:百度知道 编辑:UC知道 时间:2024/06/16 16:33:17
具体如下
1 2 6 7 14
3 5 8 13 15
4 9 12 16 19
10 11 17 18 20
N*N带文件接口


~1~~2~~6~~7~~15
-3~~5~~8~~14~16
-4~~9~~13~17~22
-10~12~18~21~23
-11~19~20~24~25-吧

var a:array[1..10,1..10]of integer;
c,i,j,d,n,l,k:integer;
b,b2:boolean;
procedure deal;
forward;
procedure zx;
begin
inc(i);
dec(j);
end;
procedure ys;
begin
dec(i);
inc(j);
end;
procedure deal;
begin
for k:=1 to n*2-3 do
begin
if not((i=1)and(j=n))then
if (i=1)or(i=n) then inc(j);
if (j=1)or(j=n) then inc(i);
if (i=1)or(j=n) then b2:=true;
if (j=1)or(i=n) then b2:=false;
if b then inc(d)
else dec(d);
if d=n then b:=false;
if b2 then repeat
inc(c);
a[i,j]:=c;
zx;
until(j=1)or(i=n)
else repeat
inc(c);
a[i,j]:=c;
ys;
until(i=1)or(j=n);
inc(c);
a[i,j]:=c;
end;
end;
begin
assign(input,'snakesquare.in');rese