Cod sursa(job #411328)

Utilizator andrey932Andrei andrey932 Data 4 martie 2010 20:32:58
Problema Hashuri Scor 70
Compilator fpc Status done
Runda Arhiva educationala Marime 1.45 kb
type pnod=^nod;
     nod=record
           v:longint;
           n:pnod;
         end;
const mo=69001;
var p,aux:pnod;
    x:array[0..mo] of pnod;
    m,i,j,tip,nr,n:longint;
    t,te:text;



function cauta(nr:longint):boolean;
begin
cauta:=false;
m:=nr mod mo;
p:=x[m];
while p<>nil do
  begin
    if p^.v=nr then
      begin
        cauta:=true;
        break;
      end;
    p:=p^.n;
  end;
end;

procedure adauga(nr:longint);
begin
m:=nr mod mo;
if (not(cauta(nr))) then
  begin
    new(p);
    p^.v:=nr;
    p^.n:=x[m];
    x[m]:=p;
  end;
end;

procedure scoate(nr:longint);
begin
m:=nr mod mo;
p:=x[m];
aux:=x[m];
if x[m]<>nil then if x[m]^.v=nr then x[m]:=x[m]^.n
else
while (p<>nil) do
  begin
    if p^.v=nr then
      begin
        aux^.n:=p^.n;
        dispose(p);
        break;
      end;
    aux:=p;
    p:=p^.n;
  end;
end;


begin
assign(t,'hashuri.in'); reset(t);
assign(te,'hashuri.out'); rewrite(te);
for i:=0 to mo do x[i]:=nil;
readln(t,n);
for i:=1 to n do
  begin
    readln(t,tip,nr);// writeln(tip,' ',nr); readln;
    if tip=1 then adauga(nr)
    else if tip=2 then scoate(nr)
    else
      begin
        if cauta(nr) then writeln(te,1)
          else writeln(te,0);
      end;
  end;
{for i:=1 to mo do
  begin
    p:=x[i];
    while p<>nil do
      begin
        writeln(p^.v);
        p:=p^.n;
      end;
  end;          readln; }
close(t);
close(te);

end.