Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.12 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp19
  4. {
  5.     class Program
  6.     {
  7.         struct Students
  8.         {
  9.             public string Name;
  10.             public int[] Exams;
  11.             public double ExamMedium;
  12.  
  13.             public Students(string Name)
  14.             {
  15.                 this.Name = Name;
  16.                 Exams = new int[5];
  17.                 ExamMedium = 0;
  18.             }
  19.  
  20.         }
  21.  
  22.         static void ExamsMedium(ref Students[,] sd)
  23.         {
  24.             for (int i = 0; i < 3; i++)
  25.             {
  26.                 for (int j = 0; j < 5; j++)
  27.                 {
  28.                     for (int k = 0; k < 5; k++)
  29.                         sd[i, 0].ExamMedium += Convert.ToDouble(sd[i, j].Exams[k]);
  30.                 }
  31.                 sd[i, 0].ExamMedium /= 5;
  32.                 for (int j = 0; j < 5; j++)
  33.                     sd[i, j].ExamMedium = sd[i, 0].ExamMedium;
  34.             }
  35.         }
  36.  
  37.         static void StudentsWrite(Students[,] sd)
  38.         {
  39.             int[] arr = new int[3] { 0, 1, 2 };
  40.  
  41.             for (int i = 0; i < 3 - 1; i++)
  42.             {
  43.                 for (int j = 0; j < 3 - i - 1; j++)
  44.                 {
  45.                     if (sd[j, 0].ExamMedium > sd[j + 1, 0].ExamMedium)
  46.                     {
  47.                         // меняем элементы местами
  48.                         int temp = arr[j];
  49.                         arr[j] = arr[j + 1];
  50.                         arr[j + 1] = temp;
  51.                     }
  52.                 }
  53.             }
  54.  
  55.             for (int i = 0; i < 3; i++)
  56.             {
  57.                 int q = arr[i];
  58.                 Console.WriteLine("{0}я группа со средним баллом {1}", i + 1, sd[q, 0].ExamMedium);
  59.                 for (int j = 0; j < 5; j++)
  60.                 {
  61.                     Console.Write("   {0}, оценки:", sd[q, j].Name);
  62.                     for (int k = 0; k < 5; k++)
  63.                     {
  64.                         Console.Write(" {0}", sd[q, j].Exams[k]);
  65.                     }
  66.                     Console.WriteLine();
  67.                 }
  68.                 Console.WriteLine();
  69.             }
  70.         }
  71.  
  72.         static void Main(string[] args)
  73.         {
  74.             Students[,] students = new Students[3, 5];
  75.  
  76.             string[,] names = new string[3, 5] { { "Петров", "Иванов", "Сидоров", "Лапенко", "Ребров" },
  77.                                                 { "Римин", "Легков", "Капица", "Смирнов", "Савенко" },
  78.                                                 { "Лазарев", "Спивак", "Юдин", "Батейко", "Рыбаков" } };
  79.  
  80.             for (int i = 0; i < 3; i++)
  81.                 for (int j = 0; j < 5; j++)
  82.                 {
  83.                     students[i, j].Name = names[i, j];
  84.                     Random rand = new Random();
  85.                     students[i, j].Exams = new int[] { rand.Next(2, 5), rand.Next(2, 5), rand.Next(2, 5), rand.Next(2, 5), rand.Next(2, 5) };
  86.                 }
  87.  
  88.             ExamsMedium(ref students);
  89.             StudentsWrite(students);
  90.             Console.ReadKey();
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement