Advertisement
mastersan12

P07.Student Academy

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