Advertisement
bacco

Average Grades

Jul 2nd, 2018
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.30 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. class Student
  7. {
  8.     public string Name { get; set; }
  9.     public List <double> Grades { get; set; }
  10.  
  11.     public double Average => Grades.Average();
  12. }
  13.  
  14. public class Example
  15. {
  16.     public static void Main()
  17.     {
  18.         int studentCount = int.Parse(Console.ReadLine());
  19.  
  20.         List<Student> students = new List<Student>();
  21.  
  22.         while (studentCount-- > 0)
  23.         {
  24.             Student student = new Student();
  25.  
  26.             string[] studentsInfo = Console.ReadLine().Split();
  27.  
  28.             student.Name   = studentsInfo[0];
  29.             student.Grades = studentsInfo
  30.                                         .Skip(1)
  31.                                         .Select(double.Parse)
  32.                                         .ToList();
  33.             students.Add(student);
  34.         }
  35.  
  36.         students.Where( s => s.Average >= 5.00 )
  37.                               .OrderBy(s => s.Name)
  38.                               .ThenByDescending(s => s.Average)
  39.                               .ToList()
  40.                               .ForEach(s =>
  41.                                {
  42.                                   Console.WriteLine($"{s.Name} -> {s.Average:F2}");
  43.                                });
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement