TheBulgarianWolf

Student Academy

Mar 3rd, 2021
1,011
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Student_Academy
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Console.WriteLine("Number of students you are about to enter: ");
  11.             int lines = int.Parse(Console.ReadLine());
  12.             Dictionary<string, double> records = new Dictionary<string, double>();
  13.             for(int i = 0; i < lines; i++)
  14.             {
  15.                 string name = Console.ReadLine();
  16.                 double grade = double.Parse(Console.ReadLine());
  17.                 if (records.ContainsKey(name))
  18.                 {
  19.                     continue;
  20.                 }
  21.                 else
  22.                 {
  23.                     records.Add(name, grade);
  24.                 }
  25.             }
  26.  
  27.             foreach(var item in records)
  28.             {
  29.                 if(item.Value < 4.50)
  30.                 {
  31.                     records.Remove(item.Key);
  32.                 }
  33.             }
  34.  
  35.             var ordered = records.OrderByDescending(g => g.Value);
  36.             foreach(var name in ordered)
  37.             {
  38.                 Console.WriteLine($"{name.Key} => {name.Value:F2}");
  39.             }
  40.         }
  41.     }
  42. }
  43.  
Add Comment
Please, Sign In to add comment