Pagini recente » Cod sursa (job #2145013) | Cod sursa (job #59779) | Cod sursa (job #2176269) | Cod sursa (job #3143367) | Cod sursa (job #945731)
Cod sursa(job #945731)
program hashuri;
type lista=^celula;
celula=record
info:longint;
next:lista;
end;
var n,x,i:longint;
op:byte;
a:array [0..100003] of lista;
r:lista;
function hash(x:longint):longint;
begin
hash:=x mod 100003;
end;
procedure insert(x:longint);
var y:longint;
begin
y:=hash(x);
new(r);
r^.info:=x;
r^.next:=a[y];
a[y]:=r;
end;
procedure delete(x:longint);
var y:longint;
begin
y:=hash(x);
r:=a[y];
if r<>nil then begin
while r^.next<>nil do
begin
if r^.next^.info=x then
begin
r^.next:=r^.next^.next;
end else r:=r^.next;
end;
if a[y]^.info=x then a[y]:=a[y]^.next;
end;
end;
function search(x:longint):byte;
var y:longint;
s:boolean;
begin
y:=hash(x);
s:=false;
r:=a[y];
while (r<>nil) and (not s)do
begin
if x=r^.info then s:=true;
r:=r^.next;
end;
if s then search:=1 else search:=0;
end;
begin
assign(input,'hashuri.in');
reset(input);
assign(output,'hashuri.out');
rewrite(output);
readln(n);
for i:=1 to n do
begin
readln(op,x);
case op of
1: insert(x);
2: delete(x);
3: writeln(search(x));
end;
end;
close(input);
close(output);
end.