Chessmaster

Untitled

Nov 6th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.IO;
  5.  
  6. namespace DICT_LMBD_And_LINQ
  7. {
  8.     class Program
  9.     {
  10.         public static void Main()
  11.         {
  12.             var gradesBy = new Dictionary<string, List<double>>();
  13.  
  14.             int n = int.Parse(Console.ReadLine());
  15.             for (int i = 0; i < n; i++)
  16.             {
  17.                 string name = Console.ReadLine();
  18.                 double grade = double.Parse(Console.ReadLine());
  19.  
  20.                 if (gradesBy.ContainsKey(name) == false)
  21.                 {
  22.                     gradesBy.Add(name, new List<double>());
  23.                 }
  24.  
  25.                 gradesBy[name].Add(grade);
  26.             }
  27.  
  28.             var sorted = gradesBy.Where(g => g.Value.Average() >= 4.50).OrderByDescending(g => g.Value.Average()).ToDictionary(x => x.Key, x => x.Value);
  29.  
  30.             foreach (var person in sorted)
  31.             {
  32.                 Console.WriteLine("{0} -> {1:f2}", person.Key, person.Value.Average());
  33.             }
  34.         }
  35.     }
  36. } // .
Advertisement
Add Comment
Please, Sign In to add comment