pascal八皇后问题 烦指出错误在哪
programproject1;vara:array[1..8,1..8]oflongint;b:array[1..8,1..8]oflongint;w,y:longin...
program project1;
var a:array[1..8,1..8] of longint;b:array[1..8,1..8] of longint;
w,y:longint;
procedure hui(i:longint);
var t,m,n:longint;
begin
if i>8 then
begin
for i:=1 to 8 do
begin
for t:=1 to 8 do
write(a[i,t]);
writeln;
end;
writeln;
write(' ');
end
else
begin
for t:=1 to 8 do
begin
if b[i,t]=0 then
begin
a[i,t]:=i;
for m:=1 to 8 do
for n:=1 to 8 do
begin
if (m+n=i+t) or (m-n=i-t) or (n=t) or (m=i) then
b[m,n]:=b[m,n]+1;
end;
end ;
hui(i+1);
a[i,t]:=0;
for m:=1 to 8 do
for n:=1 to 8 do
if (m+n=i+t) or (m-n=i-t) or (n=t) or (m=i) then
b[m,n]:=b[m,n]-1;
end;
end;
end;
begin
for w:= 1 to 8 do
for y:=1 to 8 do
begin
a[w,y]:=0;
b[w,y]:=0;
end;
hui(1);
readln;
readln;
end. 展开
var a:array[1..8,1..8] of longint;b:array[1..8,1..8] of longint;
w,y:longint;
procedure hui(i:longint);
var t,m,n:longint;
begin
if i>8 then
begin
for i:=1 to 8 do
begin
for t:=1 to 8 do
write(a[i,t]);
writeln;
end;
writeln;
write(' ');
end
else
begin
for t:=1 to 8 do
begin
if b[i,t]=0 then
begin
a[i,t]:=i;
for m:=1 to 8 do
for n:=1 to 8 do
begin
if (m+n=i+t) or (m-n=i-t) or (n=t) or (m=i) then
b[m,n]:=b[m,n]+1;
end;
end ;
hui(i+1);
a[i,t]:=0;
for m:=1 to 8 do
for n:=1 to 8 do
if (m+n=i+t) or (m-n=i-t) or (n=t) or (m=i) then
b[m,n]:=b[m,n]-1;
end;
end;
end;
begin
for w:= 1 to 8 do
for y:=1 to 8 do
begin
a[w,y]:=0;
b[w,y]:=0;
end;
hui(1);
readln;
readln;
end. 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询