Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project1;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- const
- MAXIN = 100000;
- type
- first = record
- count: integer;
- str, str1: string;
- end;
- var
- s, w, wiwod: array [1..MAXIN] of string;
- a: array [1..MAXIN] of first;
- bol: boolean;
- n, i, k, j, xint, p, z: integer;
- xstr: string;
- function min(a, b: integer): integer;
- begin
- if (a < b) then
- min := a
- else
- min := b;
- end;
- function delete1(s: string): string;
- var
- i: integer;
- begin
- i := 1;
- while (i <= length(s)) do
- if (s[i] = ' ') then
- delete(s, i, 1)
- else
- inc(i);
- delete1 := s;
- end;
- function f1(s: string): string;
- var
- x: char;
- i, j: integer;
- begin
- for i := 2 to length(s) do
- for j := length(s) downto i do
- if (s[j] < s[j - 1]) then
- begin
- x := s[j];
- s[j] := s[j - 1];
- s[j - 1] := x;
- end;
- f1 := s;
- end;
- begin
- n := 0;
- while not(eof) do
- begin
- inc(n);
- readln(s[n]);
- s[n] := delete1(s[n]);
- w[n] := f1(s[n]);
- end;
- k := 0;
- for i := 1 to n do
- begin
- bol := true;
- for j := 1 to k do
- if (w[i] = a[j].str) then
- begin
- inc(a[j].count);
- bol := false;
- break;
- end;
- if (bol) then
- begin
- inc(k);
- a[k].count := 1;
- a[k].str := w[i];
- end;
- end;
- for i := 2 to k do
- for j := k downto i do
- if (a[j].count > a[j - 1].count) then
- begin
- xint := a[j].count;
- a[j].count := a[j - 1].count;
- a[j - 1].count := xint;
- xstr := a[j].str;
- a[j].str := a[j - 1].str;
- a[j - 1].str := xstr;
- end;
- for i := 1 to k do
- begin
- p := 0;
- for j := 1 to n do
- if (w[j] = a[i].str) then
- begin
- inc(p);
- wiwod[p] := s[j];
- end;
- for z := 2 to p do
- for j := p downto z do
- if (wiwod[j] < wiwod[j - 1]) then
- begin
- xstr := wiwod[j];
- wiwod[j] := wiwod[j - 1];
- wiwod[j - 1] := xstr;
- end;
- a[i].str1 := wiwod[1];
- for j := 1 to p do
- wiwod[j] := '';
- end;
- for i := 2 to k do
- for j := k downto i do
- if (a[j].count = a[j - 1].count) then
- if (a[j].str1 < a[j - 1].str1) then
- begin
- xint := a[j].count;
- a[j].count := a[j - 1].count;
- a[j - 1].count := xint;
- xstr := a[j].str;
- a[j].str := a[j - 1].str;
- a[j - 1].str := xstr;
- xstr := a[j].str1;
- a[j].str1 := a[j - 1].str1;
- a[j - 1].str1 := xstr;
- end;
- for i := 1 to min(5, k) do
- begin
- p := 0;
- for j := 1 to n do
- if (w[j] = a[i].str) then
- begin
- inc(p);
- wiwod[p] := s[j];
- end;
- for z := 2 to p do
- for j := p downto z do
- if (wiwod[j] < wiwod[j - 1]) then
- begin
- xstr := wiwod[j];
- wiwod[j] := wiwod[j - 1];
- wiwod[j - 1] := xstr;
- end;
- write('Group of size ', a[i].count, ': ');
- for j := 1 to p do
- begin
- write(wiwod[j],' ');
- wiwod[j] := '';
- end;
- writeln('.');
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement