Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project2;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- type
- ss = string[35];
- TTree = ^Tree;
- Tree = record
- k:ss;
- l:longint;
- next:TTree;
- end;
- var
- g:ss;
- n,d,i :longint;
- f:array[0..111111] of TTree;
- function hash(x:ss):longint;
- var t,j:longint;
- begin
- t:=0;
- for j:=1 to length(x) do
- inc(t , j * 8 * ( ord(x[j]) - 96 ) );
- hash:=t;
- end;
- function count(x:ss;y:longint):longint;
- var t:TTree;
- begin
- t:=f[y];
- while t <> nil do
- begin
- if t^.k = x then
- begin
- count:=t^.l;
- inc(t^.l);
- exit;
- end;
- t:=t^.next;
- end;
- count:=0;
- end;
- function get(x:ss):longint;
- var t,ans:longint;b:TTree;
- begin
- t:=hash(x);
- ans:=count(x,t);
- if ans = 0 then
- begin
- New(b);
- b^.next:=f[t];
- f[t]:=b;
- b^.k:=x;
- b^.l:=1;
- end;
- get:=ans;
- end;
- begin
- Readln(n);
- for i:=1 to n do
- begin
- Readln(g);
- d:=get(g);
- if d = 0 then Writeln('OK')
- else Writeln(g,d);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement