fork download
  1. var strelci_tabulka, strelci: array[1..1000] of string;
  2. golov_tabulka, golov: array[1..1000] of integer;
  3. vypisany: array[1..1000] of boolean;
  4. strelec: string;
  5. i, j, aktualne_miesto, golov_minule, top_index, pocet_tabulka, pocet_strelcov, miest_tabulka: integer;
  6. nasiel: boolean;
  7. sirky: array[1..3] of integer;
  8.  
  9. procedure ciara();
  10. var i: integer;
  11. begin
  12. write('+');
  13. for i:=1 to sirky[1] do write('-');
  14. write('+');
  15. for i:=1 to sirky[2] do write('-');
  16. write('+');
  17. for i:=1 to sirky[3] do write('-');
  18. writeln('+');
  19. end;
  20.  
  21. begin
  22. {nacitame vstup}
  23. pocet_strelcov := 0;
  24. while (not EOF) do
  25. begin
  26. readln(strelec);
  27. nasiel := false;
  28. for i:=1 to pocet_strelcov do if (strelci[i] = strelec) then
  29. begin
  30. inc(golov[i]);
  31. nasiel := true;
  32. break;
  33. end;
  34. if (nasiel = false) then
  35. begin
  36. inc(pocet_strelcov);
  37. strelci[pocet_strelcov] := strelec;
  38. golov[pocet_strelcov] := 1;
  39. end;
  40. end;
  41. for i:=1 to pocet_strelcov do vypisany[i] := false;
  42.  
  43. {zistime, kto vsetko ma byt vypisany}
  44. golov_minule := 1000;
  45. miest_tabulka := 0;
  46. pocet_tabulka := 0;
  47. for i:=1 to pocet_strelcov do
  48. begin
  49. top_index := -1;
  50. for j:=1 to pocet_strelcov do if (vypisany[j] = false) then
  51. begin
  52. if (top_index < 0) then top_index := j
  53. else if (golov[j] > golov[top_index]) or ((golov[j] = golov[top_index]) and (strelci[j] < strelci[top_index])) then top_index := j;
  54. end;
  55. if (golov[top_index] < golov_minule) then inc(miest_tabulka);
  56. if (miest_tabulka > 10) then break;
  57. inc(pocet_tabulka);
  58. strelci_tabulka[pocet_tabulka] := strelci[top_index];
  59. golov_tabulka[pocet_tabulka] := golov[top_index];
  60. vypisany[top_index] := true;
  61. golov_minule := golov[top_index];
  62. end;
  63.  
  64. {poratame si, ake siroke maju byt stlpce}
  65. sirky[2] := 0;
  66. for i:=1 to pocet_tabulka do if (length(strelci_tabulka[i]) > sirky[2]) then sirky[2] := length(strelci_tabulka[i]);
  67. sirky[2] := sirky[2] + 2;
  68. sirky[3] := 3;
  69. if (golov_tabulka[1] > 10) then inc(sirky[3]);
  70. if (golov_tabulka[1] > 100) then inc(sirky[3]);
  71. sirky[1] := 4;
  72. if (miest_tabulka > 9) then inc(sirky[1]);
  73.  
  74. {samotny vypis}
  75. golov_minule := 1000;
  76. aktualne_miesto := 0;
  77. for i:=1 to pocet_tabulka do
  78. begin
  79. if (golov_tabulka[i] < golov_minule) then ciara();
  80. {stlpec s poradim}
  81. write('| ');
  82. if (golov_tabulka[i] < golov_minule) then
  83. begin
  84. inc(aktualne_miesto);
  85. write(aktualne_miesto);
  86. write('. ');
  87. if (miest_tabulka > 9) and (aktualne_miesto < 10) then write(' ');
  88. end else
  89. begin
  90. write(' ');
  91. if (miest_tabulka > 9) then write(' ');
  92. end;
  93. {stlpec s menom}
  94. write('| ', strelci_tabulka[i]);
  95. for j:=1 to sirky[2] - length(strelci_tabulka[i]) - 1 do write(' ');
  96. {stlpec s poctom golov}
  97. write('| ');
  98. if (golov_tabulka[i] < golov_minule) then
  99. begin
  100. write(golov_tabulka[i]);
  101. if (golov_tabulka[i] < 10) and (golov_tabulka[1] >= 10) then write(' ');
  102. if (golov_tabulka[i] < 100) and (golov_tabulka[1] >= 100) then write(' ');
  103. end
  104. else begin
  105. write(' ');
  106. if (golov_tabulka[1] >= 10) then write(' ');
  107. if (golov_tabulka[1] >= 100) then write(' ');
  108. end;
  109. writeln(' |');
  110. golov_minule := golov_tabulka[i];
  111. end;
  112. ciara();
  113. end.
  114.  
Success #stdin #stdout 0.01s 760KB
stdin
Standard input is empty
stdout
+----+--+---+