-
-
Save IlyaHalsky/10969039 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uses | |
SysUtils, StrUtils; | |
const | |
pr=124991; | |
type | |
List=^u; | |
u=record | |
key:Integer; | |
next:List; | |
end; | |
var | |
f,g:Text; | |
s,s1:string; | |
x,r:Integer; | |
a:array[0..pr] of List; | |
procedure inserthash(x:Integer); | |
var | |
n:Integer; | |
q,p:List; | |
begin | |
r:=0; | |
n:=Abs(x) mod pr; | |
if a[n]=nil then | |
begin | |
New(q); | |
q^.key:=x; | |
q^.next:=nil; | |
a[n]:=q; | |
end | |
else | |
begin | |
q:=a[n]; | |
while (q^.key<>x) and (q^.next<>nil) do | |
q:=q^.next; | |
if (q^.next=nil) and (q^.key<>x) then | |
begin | |
New(p); | |
p^.key:=x; | |
p^.next:=nil; | |
q^.next:=p; | |
end; | |
end; | |
end; | |
procedure DeleteHash(x:Integer); | |
var | |
n:Integer; | |
q,p:List; | |
begin | |
r:=2; | |
n:=Abs(x) mod pr; | |
if a[n]<>nil then | |
begin | |
q:=a[n]; | |
p:=nil; | |
while (q^.key<>x) and (q^.next<>nil) do | |
begin | |
p:=q; | |
q:=q^.next; | |
end; | |
if (q^.key=x) then | |
begin | |
if p=nil then | |
a[n]:=a[n]^.next | |
else | |
begin | |
p^.next:=q^.next; | |
Dispose(q); | |
end; | |
end; | |
end; | |
end; | |
procedure ExistsHash(x:Integer); | |
var | |
n:Integer; | |
q:List; | |
y:Boolean; | |
begin | |
r:=4; | |
y:=False; | |
n:=Abs(x) mod pr; | |
if a[n]<>nil then | |
begin | |
q:=a[n]; | |
while (q^.key<>x) and (q^.next<>nil) do | |
begin | |
q:=q^.next; | |
end; | |
if (q^.key=x) then | |
begin | |
y:=True; | |
end; | |
end; | |
if y=True then | |
Writeln(g,'true') | |
else | |
Writeln(g,'false'); | |
end; | |
begin | |
Assign(f,'set.in'); | |
Assign(g,'set.out'); | |
reset(f); | |
rewrite(g); | |
while not Eof(f) do | |
begin | |
Readln(f,s); | |
s1:=s[1]; | |
delete(s,1,Pos(' ',s)); | |
x:=StrToInt(s); | |
if s1='i' then | |
begin | |
inserthash(x); | |
end; | |
if s1='d' then | |
begin | |
DeleteHash(x); | |
end; | |
if s1='e' then | |
begin | |
ExistsHash(x); | |
end; | |
end; | |
close(F); | |
Close(G); | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment