Advertisement
Spocoman

06. Student Academy

Apr 8th, 2023 (edited)
988
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. using System.Threading.Channels;
  5.  
  6. namespace StudentAcademy
  7. {
  8.     class Program
  9.     {
  10.         public static void Main()
  11.         {
  12.             Dictionary<string, List<double>> studentGrades = new Dictionary<string, List<double>>();
  13.  
  14.             int n = int.Parse(Console.ReadLine());
  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 (!studentGrades.ContainsKey(student))
  22.                 {
  23.                     studentGrades.Add(student, new List<double>());
  24.                 }
  25.  
  26.                 studentGrades[student].Add(grade);
  27.             }
  28.  
  29.             foreach (var student in studentGrades)
  30.             {
  31.                 double studentAverage = student.Value.Average();
  32.                 if (studentAverage >= 4.50)
  33.                 {
  34.                     Console.WriteLine($"{student.Key} -> {studentAverage:f2}");
  35.                 }
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement