Advertisement
savrasov

Untitled

Feb 22nd, 2017
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. program Project2;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6. SysUtils;
  7. type
  8. ss = string[35];
  9. TTree = ^Tree;
  10. Tree = record
  11. k:ss;
  12. l:longint;
  13. next:TTree;
  14. end;
  15. var
  16. g:ss;
  17. n,d,i :longint;
  18. f:array[0..111111] of TTree;
  19.  
  20. function hash(x:ss):longint;
  21. var t,j:longint;
  22. begin
  23. t:=0;
  24. for j:=1 to length(x) do
  25. inc(t , j * 8 * ( ord(x[j]) - 96 ) );
  26. hash:=t;
  27. end;
  28.  
  29. function count(x:ss;y:longint):longint;
  30. var t:TTree;
  31. begin
  32. t:=f[y];
  33. while t <> nil do
  34. begin
  35. if t^.k = x then
  36. begin
  37. count:=t^.l;
  38. inc(t^.l);
  39. exit;
  40. end;
  41. t:=t^.next;
  42. end;
  43. count:=0;
  44. end;
  45.  
  46. function get(x:ss):longint;
  47. var t,ans:longint;b:TTree;
  48. begin
  49. t:=hash(x);
  50. ans:=count(x,t);
  51. if ans = 0 then
  52. begin
  53. New(b);
  54. b^.next:=f[t];
  55. f[t]:=b;
  56. b^.k:=x;
  57. b^.l:=1;
  58. end;
  59. get:=ans;
  60. end;
  61.  
  62. begin
  63. Readln(n);
  64. for i:=1 to n do
  65. begin
  66. Readln(g);
  67. d:=get(g);
  68. if d = 0 then Writeln('OK')
  69. else Writeln(g,d);
  70. end;
  71. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement