8 con hau

Màu nền
Font chữ
Font size
Chiều cao dòng

program h;

var

cot,n,i,dong:integer;

hau:array[1..10]of integer;

function xungdot(d,c:integer):boolean;

var

b:boolean;

i:integer;

b:=false;

i:=1;

while (i<c) and (not(b)) do

begin b:=(hau[i]=d)or(c-i=abs(hau[i]-d));

i:=i+1;

end;

xungdot:=b;

end;

hau[1]:=1;

cot:=2;

dong:=1;

write('nhap n:');

readln(n);

while cot>0 do

while dong<=n do

if xungdot(dong,cot)

then dong:=dong+1

else

hau[cot]:=dong;

cot:=cot+1;

dong:=1;

end;

if cot>n then

for i:=1 to n do write(hau[i]:3);

writeln;

dong:=dong+1;

end;

cot:=cot-1;

dong:=hau[cot]+1;

end;

readln;

end.

Bạn đang đọc truyện trên: Truyen2U.Pro

#con#hau