Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program sortres;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- type
- triplet = record
- a, b, c: integer;
- s: string;
- end;
- var
- i, k, n, j: integer;
- s, s1, s2: string;
- a: array [1..500] of triplet;
- procedure swap(var a, b: triplet);
- var
- c: triplet;
- begin
- c := a;
- a := b;
- b := c;
- end;
- function find(s: string): integer;
- var
- f, i: integer;
- begin
- f := 0;
- for i := 1 to k do
- if(a[i].s = s) then f := i;
- find := f;
- end;
- begin
- readln(n);
- k := 0;
- for j := 1 to n do
- begin
- readln(s);
- while (pos(' ', s) <> 0) do delete(s, pos(' ', s), 1);
- s1 := s[4] + s[5] + s[6];
- s2 := s[7] + s[8] + s[9];
- s := s[1] + s[2] + s[3];
- if(find(s) <> 0) then inc(a[find(s)].a)
- else
- begin
- inc(k);
- a[k].a := 1;
- a[k].s := s;
- end;
- if(find(s1) <> 0) then inc(a[find(s1)].b)
- else
- begin
- inc(k);
- a[k].b := 1;
- a[k].s := s1;
- end;
- if(find(s2) <> 0) then inc(a[find(s2)].c)
- else
- begin
- inc(k);
- a[k].c := 1;
- a[k].s := s2;
- end;
- end;
- for i := 1 to k + 500 do
- for j := 1 to k-1 do
- if (a[j].a < a[j + 1].a) then swap(a[j], a[j + 1])
- else if (a[j].a = a[j + 1].a) and (a[j].b < a[j + 1].b) then swap(a[j], a[j + 1])
- else if (a[j].a = a[j + 1].a) and (a[j].b = a[j + 1].b) and (a[j].c < a[j + 1].c) then swap(a[j], a[j + 1])
- else if (a[j].a = a[j + 1].a) and (a[j].b = a[j + 1].b) and (a[j].c = a[j + 1].c) and (a[j].s > a[j + 1].s) then swap(a[j], a[j + 1]);
- for i := 1 to k do writeln(a[i].s, ' ', a[i].a, ' ', a[i].b, ' ', a[i].c);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement