Cod sursa(job #410499)

Utilizator andrey932Andrei andrey932 Data 4 martie 2010 13:56:48
Problema Hashuri Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 1.22 kb
type pnod=^nod;
     nod=record
          v:integer;
          urm:pnod;
         end;
const prim=690001;

var t,te:text;
    p,aux:pnod;
    i,j,n,nr,m:longint;
    tip:byte;
    x:array[0..prim] of pnod;
  //  l:array[0..prim] of pnod;



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

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

end;

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

begin
assign(t,'hashuri.in'); reset(t);
assign(te,'hashuri.out'); rewrite(te);
readln(t,n);
for i:=1 to n do x[i]:=nil;
for i:=1 to n do
  begin
    readln(t,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(t,0);
      end;
  end;


close(t);
close(te);
end.