Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication37
  7. {
  8. class Human
  9. {
  10. public string firstName;
  11. public string surname;
  12.  
  13. public Human(string _firstName, string _surname)
  14. {
  15. firstName = _firstName;
  16. surname = _surname;
  17. }
  18. }
  19.  
  20. class Sportsman : Human
  21. {
  22. public double avg;
  23. public Sportsman(int[] results, string _firstName, string _surname)
  24. : base(_firstName, _surname)
  25. {
  26. double sum = 0;
  27. for (int i = 0; i < results.Length; i++) sum += results[i];
  28.  
  29. avg = sum / results.Length;
  30. }
  31. }
  32.  
  33.  
  34. class Program
  35. {
  36. static void Main(string[] args)
  37. {
  38. Sportsman[] firstGroup = new Sportsman[3] {
  39. new Sportsman(new int[3]{1, 4, 5}, "First1", "Sportsman11"),
  40. new Sportsman(new int[3]{3, 2, 4}, "Second1", "Sportsman12"),
  41. new Sportsman(new int[3]{2, 5, 2}, "Third1", "Sportsman13")
  42. };
  43. Sportsman[] secondGroup = new Sportsman[3] {
  44. new Sportsman(new int[3]{4, 3, 2}, "First2", "Sportsman21"),
  45. new Sportsman(new int[3]{2, 5, 3}, "Second2", "Sportsman22"),
  46. new Sportsman(new int[3]{1, 5, 2}, "Third2", "Sportsman23")
  47. };
  48. Sportsman[] allGroups = new Sportsman[6] {
  49. firstGroup[0], firstGroup[1], firstGroup[2], secondGroup[0], secondGroup[1], secondGroup[2]
  50. };
  51.  
  52. for (int i = 0; i < firstGroup.Length; i++)
  53. {
  54. for (int k = 0; k < firstGroup.Length - 1; k++)
  55. {
  56. if (firstGroup[k].avg < firstGroup[k + 1].avg)
  57. {
  58. Sportsman tmp = firstGroup[k + 1];
  59. firstGroup[k + 1] = firstGroup[k];
  60. firstGroup[k] = tmp;
  61. }
  62. }
  63. }
  64.  
  65. for (int i = 0; i < secondGroup.Length; i++)
  66. {
  67. for (int k = 0; k < secondGroup.Length - 1; k++)
  68. {
  69. if (secondGroup[k].avg < secondGroup[k + 1].avg)
  70. {
  71. Sportsman tmp = secondGroup[k + 1];
  72. secondGroup[k + 1] = secondGroup[k];
  73. secondGroup[k] = tmp;
  74. }
  75. }
  76. }
  77.  
  78.  
  79.  
  80. for (int i = 0; i < allGroups.Length; i++)
  81. {
  82. for (int k = 0; k < allGroups.Length - 1; k++)
  83. {
  84. if (allGroups[k].avg < allGroups[k + 1].avg)
  85. {
  86. Sportsman tmp = allGroups[k + 1];
  87. allGroups[k + 1] = allGroups[k];
  88. allGroups[k] = tmp;
  89. }
  90. }
  91. }
  92.  
  93. for (int i = 0; i < allGroups.Length; i++)
  94. {
  95. Console.WriteLine("Group {0}. Average = {1}", i + 1, allGroups[i].avg);
  96. }
  97. }
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement