- 神奇的幻方
- 2016-10-17 16:23:26 @
program ex1;
var s:array[1..41,1..41] of integer;
a,b,i,j,n,z:integer;
procedure wr;
begin
inc(i);
if (a=2) and (b<>n+1) then
begin
a:=n+1;
b:=b+1;
s[a,b]:=i;
if i<z then wr
else exit;
end;
if (a<>2) and (b=n+1) then
begin
a:=a-1;
b:=2;
s[a,b]:=i;
if i<z then wr
else exit;
end;
if (a=2) and (b=n+1) then
begin
a:=a+1;
s[a,b]:=i;
if i<z then wr
else exit;
end;
if (a<>2) and (b<>n+1) then
if s[a-1,b+1]=-1 then
begin
a:=a-1;
b:=b+1;
s[a,b]:=i;
if i<z then wr
else exit;
end
else
begin
a:=a+1;
s[a,b]:=i;
if i<z then wr
else exit;
end;
end;
begin
read(n);
for i:=1 to n+2 do
for j:=1 to n+2 do
s[i,j]:=0;
for i:=2 to n+1 do
for j:=2 to n+1 do
s[i,j]:=-1;
z:=n*n;
i:=1;
a:=2;
b:=(n div 2)+2;
s[a,b]:=1;
wr;
for i:=2 to n+1 do
begin
for j:=2 to n do
write(s[i,j],' ');
writeln(s[i,n+1]);
end;
end.
2 条评论
-
小智障 LV 7 @ 2016-10-17 16:37:34
已解决……但是哪位大神可以解释一下为什么数组开到120而程序没改就过了……
-
2016-10-17 16:33:59@
改了下程序……但还是一到15就201……求大神解答
program ex1;
var s:array[1..41,1..41] of integer;
a,b,i,j,n,z:integer;
procedure wr;
begin
inc(i);
if (a=2) and (b<>n+1) then
begin
a:=n+1;
b:=b+1;
s[a,b]:=i;
if i<z then wr
else exit;
end;
if (a<>2) and (b=n+1) then
begin
a:=a-1;
b:=2;
s[a,b]:=i;
if i<z then wr
else exit;
end;
if s[a-1,b+1]=-1 then
begin
a:=a-1;
b:=b+1;
s[a,b]:=i;
if i<z then wr
else exit;
end
else
begin
a:=a+1;
s[a,b]:=i;
if i<z then wr
else exit;
end;
end;
begin
read(n);
for i:=1 to n+2 do
for j:=1 to n+2 do
s[i,j]:=0;
for i:=2 to n+1 do
for j:=2 to n+1 do
s[i,j]:=-1;
z:=n*n;
i:=1;
a:=2;
b:=(n div 2)+2;
s[a,b]:=1;
wr;
for i:=2 to n+1 do
begin
for j:=2 to n do
write(s[i,j],' ');
writeln(s[i,n+1]);
end;
end.
- 1
信息
- ID
- 1978
- 难度
- 2
- 分类
- (无)
- 标签
- 递交数
- 2443
- 已通过
- 1340
- 通过率
- 55%
- 被复制
- 9
- 上传者