|
|
back to boardShow all messages Hide all messages> Just insert numbers to the binary tree and then print them in the order you want. Yeah!! Try to see structure of input and output strings. Resursion-recursion. program timus1136a; {$APPTYPE CONSOLE} uses SysUtils; const mz=100000; var a,b:array[0..3000] of longint;n,i,p,q:longint; procedure f(u,r,t:longint);begin if(a[u]<r){l} then begin p:=u;exit;end; f(u-1,a[u],t); f(p,r,a[u]); inc(q);b[q]:=a[u];if u<=p then p:=u-1; end; begin read(n); for i := 1 to n do read(a[i]);a[0]:=-1; p:=n;q:=0; f(n,0,mz); for i := 1 to n-1 do write(b[i],' ');write(b[n]);
end. |
|
|