fork(1) download
  1. type
  2. TArr = array [1..100] of record
  3. value, cnt : Integer
  4. end;
  5.  
  6. function PopMax(var a : TArr; const n : Integer) : Integer;
  7. var
  8. m, i : Integer;
  9. begin
  10. m := 1;
  11. for i := 2 to n do
  12. if a[i].cnt > a[m].cnt then m := i;
  13.  
  14. PopMax := a[m].value;
  15. a[m].cnt := -1
  16. end;
  17.  
  18. var
  19. n, m, i, j, k : Integer;
  20. b : array [1..100, 1..100] of Integer;
  21. a : TArr;
  22.  
  23. begin
  24. ReadLn(n);
  25. for i := 1 to n do begin
  26. Read(a[i].value);
  27. a[i].cnt := 0
  28. end;
  29.  
  30. ReadLn(m);
  31. for i := 1 to m do
  32. for j := 1 to n do
  33. Read(b[i, j]);
  34.  
  35.  
  36. for k := 1 to n do
  37. for i := 1 to m do
  38. for j := 1 to n do
  39. if b[i, j] = a[k].value then begin
  40. Inc(a[k].cnt); Break;
  41. end;
  42.  
  43. WriteLn(PopMax(a, n), ' ', PopMax(a, n), ' ', PopMax(a, n))
  44. end.
Success #stdin #stdout 0s 252KB
stdin
5
84 51 87 23 57
10
94 10 88 48 32
50 44 65 60 21
37 32 34 88 10
60 94 30 18 27
27 89 78 31 14
67 23 84 51 43
32 78 98 29 96
11 69 84 51 23
30 45 91 93 29
28 10 29 56 93
stdout
84 51 23