Advertisement
savrasov

FFFFF

Jan 12th, 2017
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program sfdsf;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils;
  7.  
  8. type
  9.   triplet = record
  10.     a, b, c: integer;
  11.     s: string;
  12.   end;
  13.  
  14. var
  15.   f, i, k, n, j: integer;
  16.   s, s1, s2: string;
  17.   b, b1, b2: boolean;
  18.   a: array [1..100000] of triplet;
  19.  
  20. procedure swap(var a, b: triplet);
  21. var
  22.   c: triplet;
  23. begin
  24.   c := a;
  25.   a := b;
  26.   b := c;
  27. end;
  28.  
  29. function fff(s, s1: string): boolean;
  30. var
  31.   i: integer;
  32. begin
  33.   for i := 1 to 3 do
  34.     if(ord(s[i]) < ord(s1[i])) then
  35.     begin
  36.       fff := true;
  37.       exit;
  38.     end;
  39.   fff := false;
  40. end;
  41.  
  42. begin
  43.   readln(n);
  44.   k := 0;
  45.   for j := 1 to n do
  46.   begin
  47.     readln(s);
  48.     b := false;
  49.     b1 := false;
  50.     b2 := false;
  51.     s1 := s[5] + s[6] + s[7];
  52.     s2 := s[9] + s[10] + s[11];
  53.     s := s[1] + s[2] + s[3];
  54.     for i := 1 to k do
  55.     begin
  56.       if (s = a[i].s) then
  57.       begin
  58.         inc(a[i].a);
  59.         b := true;
  60.       end;
  61.       if (s1 = a[i].s) then
  62.       begin
  63.         inc(a[i].b);
  64.         b1 := true;
  65.       end;
  66.       if (s2 = a[i].s) then
  67.       begin
  68.         inc(a[i].c);
  69.         b2 := true;
  70.       end;
  71.     end;
  72.     if (not b) then
  73.     begin
  74.       inc(k);
  75.       a[k].s := s;
  76.       a[k].a := 1;
  77.     end;
  78.     if (not b1) then
  79.     begin
  80.       if(s1 <> a[k].s) then inc(k);
  81.       a[k].s := s1;
  82.       inc(a[k].b);
  83.     end;
  84.     if (not b2) then
  85.     begin
  86.       if(s2 = a[k - 1].s) then inc(a[k-1].c)
  87.       else if (s2 = a[k].s) then inc(a[k].c)
  88.       else
  89.       begin
  90.         inc(k);
  91.         a[k].s := s2;
  92.         a[k].c := 1;
  93.       end;
  94.     end;
  95.   end;
  96.   for i := 1 to k do
  97.     for j := 1 to k do
  98.       if (a[j].a > a[j + 1].a) then swap(a[j], a[j + 1])
  99.         else if (a[j].a = a[j + 1].a) and (a[j].b > a[j + 1].b) then swap(a[j], a[j + 1])
  100.           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])
  101.             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 (fff(a[j].s, a[j + 1].s)) then swap(a[j], a[j + 1]);
  102.   for i := k + 1 downto 2 do writeln(a[i].s, ' ', a[i].a, ' ', a[i].b, ' ', a[i].c);
  103. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement