Cod sursa(job #1313793)

Utilizator valen.valentinValentin Valeanu valen.valentin Data 11 ianuarie 2015 09:49:59
Problema Hashuri Scor 70
Compilator fpc Status done
Runda Arhiva educationala Marime 1.4 kb
program hash;
const modd=666013;
type
lista=^date;
date=record
m:longint;
next:lista;
end;
tabel=array[0..modd+1] of lista;
buf=array[0..1 shl 17] of char;
var
ff1,ff2:buf;
t:tabel; a:lista;
n,x,tip,i:longint;
f1,f2:text;
function chech(a,b:longint):boolean;
var ok:boolean; aa:lista;
begin
ok:=false; aa:=t[a];
while (aa<>nil) and not ok do begin
if aa^.m=b then begin ok:=true;break; end else
aa:=aa^.next;
end;
chech:=ok;
end;
procedure add_hash(x:longint);
begin
if not chech(x mod modd,x) then begin new(a); a^.m:=x; a^.next:=t[x mod modd]; t[x mod modd]:=a; end;
end;
procedure del(var a:lista;x:longint);
var i:longint; z:lista;
begin
i:=0; z:=a;
if z^.next=nil then a:=nil else begin
while (i<x-1) do begin
z:=z^.next; i:=i+1;
end;
if z^.next<>nil then z^.next:=z^.next^.next;
end; end;
procedure del_hash(x:longint);
var a:lista; k:longint;
begin
a:=t[x mod modd]; k:=0;
while a<>nil do begin
k:=k+1;
if a^.m=x then begin
if a^.next=nil then begin del(t[x mod modd],k); break; end; end;
a:=a^.next;
end;
end;
begin
assign (f1,'hashuri.in');
assign (f2,'hashuri.out');
reset (f1);
rewrite (f2);
settextbuf(f1,ff1);
settextbuf(f2,ff2);
readln (f1,n);
for i:=1 to n do begin
readln (f1,tip,x);
case tip of
1:add_hash(x);
2:del_hash(x);
3:begin
if chech(x mod modd,x) then writeln (f2,1) else
writeln (f2,0);
end; end;
end;
close (f1);
close (f2);
end.