Cod sursa(job #36109)

Utilizator vanila0406Ionescu Victor vanila0406 Data 22 martie 2007 23:26:54
Problema Schi Scor 50
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.63 kb
program schi;
type arbore=^nod;
        nod=record
                id,loc:longint;
                st,dr:arbore;
end;
var r:arbore;
        f,g:text;
        n:longint;

procedure mar1(r:arbore);
begin
        if r<>nil then
                begin
                        inc(r^.loc);
                        mar1(r^.st);
                        mar1(r^.dr);
                end;
end;


procedure create(var r:arbore;x,y:longint);
begin
        if r=nil then
                begin
                        new(r);
                        r^.id:=x;
                        r^.loc:=y;
                        r^.st:=nil;
                        r^.dr:=nil;
                end else
                if y<=r^.loc then
                        begin
                                inc(r^.loc);
                                mar1(r^.dr);
                                create(r^.st,x,y);
                        end else
                        create(r^.dr,x,y);
end;


procedure iofile;
var i,x:longint;
begin

        assign(f,'schi.in');
        reset(f);
        assign(g,'schi.out');
        rewrite(g);
        readln(f,n);
        r:=nil;
        for i:=1 to n do
                begin
                        readln(f,x);
                        create(r,i,x);
                end;
        close(f);
end;



procedure srd(r:arbore);
begin
        if r<>nil then
                begin
                        srd(r^.st);
                        writeln(g,r^.id);
                        srd(r^.dr);
                end;
end;



begin
        iofile;
        srd(r);
        close(g);
end.