Advertisement
AlexTasev

04_AverageGrades

Jun 15th, 2018
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04_AverageGrades
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             int studentsCount = int.Parse(Console.ReadLine());
  12.  
  13.             List<Student> excelentStudents = new List<Student>();
  14.  
  15.             for (int i = 0; i < studentsCount; i++)
  16.             {
  17.                 List<string> input = Console.ReadLine()
  18.                     .Split()
  19.                     .ToList();
  20.  
  21.                 string studentName = input[0];
  22.  
  23.                 input.Remove(input[0]);
  24.  
  25.                 List<double> listGrades = input.Select(double.Parse).ToList();
  26.  
  27.                 Student student = new Student(studentName, listGrades);
  28.  
  29.                 if (student.AverageGrade >= 5.00)
  30.                 {
  31.                     excelentStudents.Add(student);
  32.                 }
  33.             }
  34.  
  35.             excelentStudents = excelentStudents
  36.                 .OrderBy(st => st.Name)
  37.                 .ThenByDescending(st => st.AverageGrade)
  38.                 .ToList();
  39.  
  40.             foreach (var student in excelentStudents)
  41.             {
  42.                 Console.WriteLine($"{student.Name} -> {student.AverageGrade:f2}");
  43.             }
  44.         }
  45.     }
  46.  
  47.     public class Student
  48.     {
  49.         public Student(string studentName, List<double> listGrades)
  50.         {
  51.             Name = studentName;
  52.             ListGrades = listGrades;
  53.             AverageGrade = listGrades.Average();
  54.         }
  55.         public string Name { get; set; }
  56.         public List<double> ListGrades { get; set; }
  57.         public double AverageGrade { get; set; }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement