Advertisement
Guest User

04. Average Grades

a guest
Sep 9th, 2016
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 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(string[] args)
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.             List<Student> list = new List<Student>();
  13.             SortedList<string, double> ByName = new SortedList<string, double>();
  14.  
  15.             for (int i = 0; i < n; i++)
  16.             {
  17.                 string[] input = Console.ReadLine().Split(' ');
  18.                 List<double> grades = input.Skip(1).Select(double.Parse).ToList();
  19.                 list.Add(new Student(input[0], grades));
  20.             }
  21.             foreach(var s in list)
  22.             {
  23.                 if(s.GetAvgGrade() > 5.00)
  24.                 {
  25.                     ByName.Add(s.GetName(), s.GetAvgGrade());
  26.                 }
  27.             }
  28.  
  29.             Console.WriteLine(string.Join("\r\n", ByName));
  30.         }
  31.  
  32.         class Student
  33.         {
  34.             private string _name;
  35.             private List<double> _grades;
  36.             private double _averageGrade;
  37.  
  38.             public Student(string name, List<double> grades)
  39.             {
  40.                 this._name = name;
  41.                 this._grades = grades;
  42.                 this._averageGrade = grades.Average();
  43.             }
  44.  
  45.             public string GetName()
  46.             {
  47.                 return this._name;
  48.             }
  49.  
  50.             public double GetAvgGrade()
  51.             {
  52.                 return this._averageGrade;
  53.             }
  54.  
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement