Advertisement
Guest User

Untitled

a guest
Sep 9th, 2016
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 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.             list.OrderBy(x => x._name).ThenBy(x => x._averageGrade);
  22.  
  23.             Console.WriteLine(string.Join("\r\n", list.Where(x => x._averageGrade > 5.00)));
  24.         }
  25.  
  26.         class Student
  27.         {
  28.             public string _name;
  29.             public List<double> _grades;
  30.             public double _averageGrade;
  31.  
  32.             public Student(string name, List<double> grades)
  33.             {
  34.                 this._name = name;
  35.                 this._grades = grades;
  36.                 this._averageGrade = grades.Average();
  37.             }
  38.  
  39.             public override string ToString()
  40.             {
  41.                 return string.Format("{0} -> {1:F2}", this._name, this._averageGrade);
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement