Advertisement
savrasov

dfuhhufdjlgkdjgdfjkg;jfkdl;g

Jan 15th, 2017
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. program sortres;
  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. i, k, n, j: integer;
  16. s, s1, s2: string;
  17. a: array [1..500] of triplet;
  18.  
  19. procedure swap(var a, b: triplet);
  20. var
  21. c: triplet;
  22. begin
  23. c := a;
  24. a := b;
  25. b := c;
  26. end;
  27.  
  28. function find(s: string): integer;
  29. var
  30. f, i: integer;
  31. begin
  32. f := 0;
  33. for i := 1 to k do
  34. if(a[i].s = s) then f := i;
  35. find := f;
  36. end;
  37.  
  38. begin
  39. readln(n);
  40. k := 0;
  41. for j := 1 to n do
  42. begin
  43. readln(s);
  44. while (pos(' ', s) <> 0) do delete(s, pos(' ', s), 1);
  45. s1 := s[4] + s[5] + s[6];
  46. s2 := s[7] + s[8] + s[9];
  47. s := s[1] + s[2] + s[3];
  48. if(find(s) <> 0) then inc(a[find(s)].a)
  49. else
  50. begin
  51. inc(k);
  52. a[k].a := 1;
  53. a[k].s := s;
  54. end;
  55. if(find(s1) <> 0) then inc(a[find(s1)].b)
  56. else
  57. begin
  58. inc(k);
  59. a[k].b := 1;
  60. a[k].s := s1;
  61. end;
  62. if(find(s2) <> 0) then inc(a[find(s2)].c)
  63. else
  64. begin
  65. inc(k);
  66. a[k].c := 1;
  67. a[k].s := s2;
  68. end;
  69. end;
  70. for i := 1 to k + 500 do
  71. for j := 1 to k-1 do
  72. if (a[j].a < a[j + 1].a) then swap(a[j], a[j + 1])
  73. else if (a[j].a = a[j + 1].a) and (a[j].b < a[j + 1].b) then swap(a[j], a[j + 1])
  74. 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])
  75. 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]);
  76. for i := 1 to k do writeln(a[i].s, ' ', a[i].a, ' ', a[i].b, ' ', a[i].c);
  77. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement