Cod sursa(job #1168032)

Utilizator Mihai_ChihaiMihai Chihai Mihai_Chihai Data 6 aprilie 2014 18:25:31
Problema Hashuri Scor 30
Compilator fpc Status done
Runda Arhiva educationala Marime 1.34 kb
program hashuri;
 const p=666013;
 type lista=^celula;
     celula=record
        info:longint;
        pred:lista;
        end;
 var a:array[0..p] of lista;
     n,i,op,x:longint;
     r:lista;
     gasit:boolean;
 begin
   assign(input,'hashuri.in');
   assign(output,'hashuri.out');
   reset(input);
   rewrite(output);
   readln(n);
   while (n>0) do
     begin
      readln(op,x);
      if op=1 then
       begin
         new(r);
         r^.info:=x;
         r^.pred:=a[x mod p];
         a[x mod p]:=r;
       end;
      if op=2 then
        begin
         r:=a[x mod p];
         if r<>nil then
           if r^.info=x then
                 a[x mod p]:=a[x mod p]^.pred
                 else
                begin
                 while (r^.pred<>nil)
                  do begin
                   if r^.pred^.info=x
                    then r:=r^.pred^.pred;
                    r:=r^.pred;
                    end;
                 end;
         end;
     if op=3 then
      begin
        r:=a[x mod p];
        gasit:=false;
        while (r<>nil) and(not gasit)do
          begin
            if r^.info=x then
             gasit:=true;
            r:=r^.pred;
          end;
        if gasit then writeln(1)
                 else writeln(0);
      end;
     dec(n);
   end;
  close(output);
  end.