Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication37
- {
- class Human
- {
- public string firstName;
- public string surname;
- public Human(string _firstName, string _surname)
- {
- firstName = _firstName;
- surname = _surname;
- }
- }
- class Sportsman : Human
- {
- public double avg;
- public Sportsman(int[] results, string _firstName, string _surname)
- : base(_firstName, _surname)
- {
- double sum = 0;
- for (int i = 0; i < results.Length; i++) sum += results[i];
- avg = sum / results.Length;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Sportsman[] firstGroup = new Sportsman[3] {
- new Sportsman(new int[3]{1, 4, 5}, "First1", "Sportsman11"),
- new Sportsman(new int[3]{3, 2, 4}, "Second1", "Sportsman12"),
- new Sportsman(new int[3]{2, 5, 2}, "Third1", "Sportsman13")
- };
- Sportsman[] secondGroup = new Sportsman[3] {
- new Sportsman(new int[3]{4, 3, 2}, "First2", "Sportsman21"),
- new Sportsman(new int[3]{2, 5, 3}, "Second2", "Sportsman22"),
- new Sportsman(new int[3]{1, 5, 2}, "Third2", "Sportsman23")
- };
- Sportsman[] allGroups = new Sportsman[6] {
- firstGroup[0], firstGroup[1], firstGroup[2], secondGroup[0], secondGroup[1], secondGroup[2]
- };
- for (int i = 0; i < firstGroup.Length; i++)
- {
- for (int k = 0; k < firstGroup.Length - 1; k++)
- {
- if (firstGroup[k].avg < firstGroup[k + 1].avg)
- {
- Sportsman tmp = firstGroup[k + 1];
- firstGroup[k + 1] = firstGroup[k];
- firstGroup[k] = tmp;
- }
- }
- }
- for (int i = 0; i < secondGroup.Length; i++)
- {
- for (int k = 0; k < secondGroup.Length - 1; k++)
- {
- if (secondGroup[k].avg < secondGroup[k + 1].avg)
- {
- Sportsman tmp = secondGroup[k + 1];
- secondGroup[k + 1] = secondGroup[k];
- secondGroup[k] = tmp;
- }
- }
- }
- for (int i = 0; i < allGroups.Length; i++)
- {
- for (int k = 0; k < allGroups.Length - 1; k++)
- {
- if (allGroups[k].avg < allGroups[k + 1].avg)
- {
- Sportsman tmp = allGroups[k + 1];
- allGroups[k + 1] = allGroups[k];
- allGroups[k] = tmp;
- }
- }
- }
- for (int i = 0; i < allGroups.Length; i++)
- {
- Console.WriteLine("Group {0}. Average = {1}", i + 1, allGroups[i].avg);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement