Teo_Yanchev

07. StudentAcademy - Dictionary - C# Fundmentals

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