Advertisement
elena1234

StudentAcademy*

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