Advertisement
tanya_zheleva

Untitled

Feb 12th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04.Average_Grades
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.             var finalResult = new List<Student>();
  13.  
  14.             for (int i = 0; i < n; i++)
  15.             {
  16.                 var inputData = Console.ReadLine().Split(' ');
  17.  
  18.                 var currentStudent = new Student
  19.                 {
  20.                     Name = inputData[0],
  21.                     Grades = inputData.Skip(1).Select(double.Parse).ToArray(),
  22.                 };
  23.  
  24.                 if (currentStudent.AverageGrade >= 5.00)
  25.                 {
  26.                     finalResult.Add(currentStudent);
  27.                 }
  28.             }
  29.  
  30.             foreach (var student in finalResult.OrderBy(s => s.Name).ThenByDescending(s => s.AverageGrade))
  31.             {
  32.                 Console.WriteLine($"{student.Name} -> {student.AverageGrade:f2}");
  33.             }
  34.         }
  35.     }
  36.  
  37.     class Student
  38.     {
  39.         public string Name { get; set; }
  40.  
  41.         public double[] Grades { get; set; }
  42.  
  43.         public double AverageGrade => this.Grades.Average();
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement