其实,用ansistring会更快,我们可以逐步分层计算。
var
n,n1,i,w,stt,j:longint;
bo:boolean;
a:array[0..10,0..1024] of ansistring;
procedure yu(flo,cen:longint);{逐步处理}
begin
if flo>n then exit;
for i:=1 to cen do a[flo,i]:=a[flo-1,i];
stt:=length(a[flo-1,cen]);{第一块,有一块三角形}
for i:=1 to cen do begin
a[flo,i+cen]:=a[flo-1,i];
for j:=1 to stt-2*i do a[flo,i+cen]:=a[flo,i+cen]+' ';
a[flo,i+cen]:=a[flo,i+cen]+a[flo-1,i];{第二块,有两块三角形}
end;
yu(flo+1,cen*2);{继续递归}
end;
begin
readln(n);
a[1,1]:='/';{第一层}
a[1,2]:='/__';
yu(2,2);
n1:=1;
w:=1;
for i:=1 to n do n1:=n1*2;
dec(n1);
repeat
for i:=1 to n1 do write(' ');{w是空格数}
writeln(a[n,w]);
dec(n1); inc(w);
until n1<0;
end.
仅供参考,希望能对你有所帮助。