1樓:
program tt;
var a:array [1..100] of integer;
b,c,d:array [-100..200] of integer;
t,i,j,k:integer;
procedure print;
begin
t:=t+1;
write(t,' ');
for k:=1 to n do write(a[k],' ');
writeln;
end;
procedure try(i:integer);
var j:integer;
begin
for j:=1 to n do
if (b[j]=0) and (c[i+j]=0) and (d[i-j]=0) then
begin
a[i]:=j;
b[j]:=1;
c[i+j]:=1;
d[i-j]:=1;
if i else print; b[j]:=0; c[i+j]:=0; d[i-j]:=0; end; end; begin readln(n); try(1); end. 另附八皇后: program tt; var a:array [1..8] of integer; b,c,d:array [-7..16] of integer; t,i,j,k:integer; procedure print; begin t:=t+1; write(t,' '); for k:=1 to 8 do write(a[k],' '); writeln; end; procedure try(i:integer); var j:integer; begin for j:=1 to 8 do if (b[j]=0) and (c[i+j]=0) and (d[i-j]=0) then begin a[i]:=j; b[j]:=1; c[i+j]:=1; d[i-j]:=1; if i<8 then try(i+1) else print; b[j]:=0; c[i+j]:=0; d[i-j]:=0; end; end; begin for k:=-7 to 16 do begin b[k]:=0; c[k]:=0; d[k]:=0; end; try(1); end. 2樓:匿名使用者 program bahuanghou; var a:array[1..20] of integer; b:array[1..20] of boolean; c:array[-19..19] of boolean; m:array[2..40] of boolean; x,y,n,k:integer; procedure print; var t,p:integer; begin t:=t+1; write(t,' '); for p:=1 to k do write(a[p],' '); writeln; end; procedure try(x:integer); var y:integer; begin for y:=1 to k do begin if (b[y]=true) and (c[x-y]=true) and (m[x+y]=true) then begin a[x]:=y; b[y]:=false; c[x-y]:=false; m[x+y]:=false; if x<8 then try(x+1) else print; b[y]:=true; c[x-y]:=true; m[x+y]:=true; end; end; end; begin readln(k); for n:=1 to k do b[n]:=true; for n:=-k+1 to k-1 do c[n]:=true; for n:=2 to 2*k do m[n]:=true; try(1); readln; end. 應該就是這樣的了,還可以再優化一下的,自己想吧 pascal博士 var f array a d of boolean s longint ch char begin for ch a to d dobegin f ch true 列舉誰是小偷,做標記s 0 說真話數量計數器 if not f a then inc s a不是小偷則計數器加一 i... 我剛剛自己編的 試過了 肯定對 程式中公雞數量為a 母雞數量為b 小雞數量為c 輸出順序為 a1 b1 c1 a2 b2 c2 如下 for迴圈 vara,b,c integer begin for a 1 to 100 div 3 do for b 1 to 100 a div 2 do begi... vara longint function ok x longint boolean var i longint begin for i 2 to trunc sqrt x doif x mod i 0 then exit false exit true end begin readln a if ...Pascal程式設計題答案,pascal程式設計題目,大師解答一下,最好用最簡潔的方法,做上批註。
PASCAL程式設計問題,PASCAL程式設計問題
pascal程式設計給出整數n讓你判斷n是否是素數