Advertisement
Dennnhhhickk

Untitled

Nov 29th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. program Project1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6. SysUtils;
  7.  
  8. const
  9. MAXIN = 100000;
  10.  
  11. type
  12. first = record
  13. count: integer;
  14. str, str1: string;
  15. end;
  16.  
  17. var
  18. s, w, wiwod: array [1..MAXIN] of string;
  19. a: array [1..MAXIN] of first;
  20. bol: boolean;
  21. n, i, k, j, xint, p, z: integer;
  22. xstr: string;
  23.  
  24. function min(a, b: integer): integer;
  25. begin
  26. if (a < b) then
  27. min := a
  28. else
  29. min := b;
  30. end;
  31.  
  32. function delete1(s: string): string;
  33. var
  34. i: integer;
  35. begin
  36. i := 1;
  37. while (i <= length(s)) do
  38. if (s[i] = ' ') then
  39. delete(s, i, 1)
  40. else
  41. inc(i);
  42. delete1 := s;
  43. end;
  44.  
  45. function f1(s: string): string;
  46. var
  47. x: char;
  48. i, j: integer;
  49. begin
  50. for i := 2 to length(s) do
  51. for j := length(s) downto i do
  52. if (s[j] < s[j - 1]) then
  53. begin
  54. x := s[j];
  55. s[j] := s[j - 1];
  56. s[j - 1] := x;
  57. end;
  58. f1 := s;
  59. end;
  60.  
  61. begin
  62. n := 0;
  63.  
  64. while not(eof) do
  65. begin
  66. inc(n);
  67. readln(s[n]);
  68. s[n] := delete1(s[n]);
  69. w[n] := f1(s[n]);
  70. end;
  71.  
  72. k := 0;
  73.  
  74. for i := 1 to n do
  75. begin
  76. bol := true;
  77. for j := 1 to k do
  78. if (w[i] = a[j].str) then
  79. begin
  80. inc(a[j].count);
  81. bol := false;
  82. break;
  83. end;
  84. if (bol) then
  85. begin
  86. inc(k);
  87. a[k].count := 1;
  88. a[k].str := w[i];
  89. end;
  90. end;
  91.  
  92. for i := 2 to k do
  93. for j := k downto i do
  94. if (a[j].count > a[j - 1].count) then
  95. begin
  96. xint := a[j].count;
  97. a[j].count := a[j - 1].count;
  98. a[j - 1].count := xint;
  99. xstr := a[j].str;
  100. a[j].str := a[j - 1].str;
  101. a[j - 1].str := xstr;
  102. end;
  103.  
  104. for i := 1 to k do
  105. begin
  106. p := 0;
  107. for j := 1 to n do
  108. if (w[j] = a[i].str) then
  109. begin
  110. inc(p);
  111. wiwod[p] := s[j];
  112. end;
  113. for z := 2 to p do
  114. for j := p downto z do
  115. if (wiwod[j] < wiwod[j - 1]) then
  116. begin
  117. xstr := wiwod[j];
  118. wiwod[j] := wiwod[j - 1];
  119. wiwod[j - 1] := xstr;
  120. end;
  121. a[i].str1 := wiwod[1];
  122. for j := 1 to p do
  123. wiwod[j] := '';
  124. end;
  125.  
  126. for i := 2 to k do
  127. for j := k downto i do
  128. if (a[j].count = a[j - 1].count) then
  129. if (a[j].str1 < a[j - 1].str1) then
  130. begin
  131. xint := a[j].count;
  132. a[j].count := a[j - 1].count;
  133. a[j - 1].count := xint;
  134. xstr := a[j].str;
  135. a[j].str := a[j - 1].str;
  136. a[j - 1].str := xstr;
  137. xstr := a[j].str1;
  138. a[j].str1 := a[j - 1].str1;
  139. a[j - 1].str1 := xstr;
  140. end;
  141.  
  142. for i := 1 to min(5, k) do
  143. begin
  144. p := 0;
  145. for j := 1 to n do
  146. if (w[j] = a[i].str) then
  147. begin
  148. inc(p);
  149. wiwod[p] := s[j];
  150. end;
  151. for z := 2 to p do
  152. for j := p downto z do
  153. if (wiwod[j] < wiwod[j - 1]) then
  154. begin
  155. xstr := wiwod[j];
  156. wiwod[j] := wiwod[j - 1];
  157. wiwod[j - 1] := xstr;
  158. end;
  159. write('Group of size ', a[i].count, ': ');
  160. for j := 1 to p do
  161. begin
  162. write(wiwod[j],' ');
  163. wiwod[j] := '';
  164. end;
  165. writeln('.');
  166. end;
  167.  
  168. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement