Cod sursa(job #36670)
Utilizator | Ionescu Victor vanila0406 | Data | 23 martie 2007 22:54:28 |
---|---|---|---|
Problema | Schi | Scor | 10 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 1.76 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
begin
if r^.dr<>nil then r^.dr^.loc:=r^.loc+1;
create(r^.dr,x,y);
end;
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.