Advertisement
ralichka

academy

Nov 19th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _07.StudentAcademy
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.  
  13.             Dictionary<string, List<double>> information = new Dictionary<string, List<double>>();
  14.             Dictionary<string, List<double>> result = new Dictionary<string, List<double>>();
  15.  
  16.             for (int i = 0; i < n; i++)
  17.             {
  18.                 string student = Console.ReadLine();
  19.                 double grade = double.Parse(Console.ReadLine());
  20.  
  21.                 if (!information.ContainsKey(student))
  22.                 {
  23.                     //information.Add(student, new List<double>());
  24.                     information[student] = new List<double>();
  25.                 }
  26.                 information[student].Add(grade);
  27.             }
  28.  
  29.             result = information
  30.                  .Where(x => x.Value.Average() >= 4.5)
  31.                  .OrderByDescending(x => x.Value.Average())
  32.                  .ToDictionary(x => x.Key,
  33.                                x => x.Value);
  34.  
  35.             foreach (var item in result)
  36.             {
  37.                 Console.WriteLine($"{item.Key} -> {item.Value:f2}");
  38.             }
  39.  
  40.  
  41.             //foreach (var eachStudent in information.OrderByDescending(x=>x.Value.Average()))
  42.             //{
  43.             //    if (eachStudent.Value.Average() >= 4.50)
  44.             //    {
  45.             //        Console.WriteLine($"{eachStudent.Key} -> {eachStudent.Value.Average():f2}");
  46.             //    }
  47.             //}
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement