anizko

10. SoftUni Exam Results

Jul 13th, 2019
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _10._SoftUni_Exam_Results
  6. {
  7.  class Student
  8.     {
  9.      
  10.         public string Course { get; set; }
  11.         public int Points { get; set; }
  12.    
  13.  
  14.         public Student(string course, int pionts)
  15.         {
  16.             Course = course;
  17.             Points = pionts;
  18.         }
  19.     }
  20.     class Program
  21.     {
  22.         static void Main(string[] args)
  23.         {
  24.             Dictionary<string, Student> dictMax = new Dictionary<string, Student>();
  25.             Dictionary<string, int> dictCount = new Dictionary<string, int>();
  26.  
  27.             string comand = Console.ReadLine();
  28.  
  29.             while(comand!= "exam finished")
  30.             {
  31.                 string[] info = comand.Split('-');
  32.                 string name = info[0];
  33.  
  34.                 if (info[1]== "banned")
  35.                 {
  36.                     dictMax = dictMax.Where(x => x.Key != name).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
  37.                 }
  38.                 else
  39.                 {
  40.                     string course = info[1];
  41.                     int points = int.Parse(info[2]);
  42.  
  43.                     if(! dictCount.ContainsKey(course))
  44.                     {
  45.                         dictCount[course] = 0;
  46.                     }
  47.                     dictCount[course]++;
  48.  
  49.                     if(! dictMax.ContainsKey(name))
  50.                     {
  51.                         dictMax[name] = new Student(course, points);
  52.                     }
  53.                    
  54.                     foreach(var item in dictMax.Where(x=>x.Key==name && x.Value.Course==course))
  55.                     {
  56.                         if( item.Value.Points<points)
  57.                         {
  58.                             item.Value.Points = points;
  59.                         }
  60.                     }
  61.                 }
  62.  
  63.                 comand = Console.ReadLine();
  64.             }
  65.  
  66.             Console.WriteLine("Results:");
  67.  
  68.             foreach(var item in dictMax.OrderByDescending(x=>x.Value.Points).ThenBy(x => x.Key))
  69.             {
  70.                 Console.WriteLine($"{item.Key} | {item.Value.Points}");
  71.             }
  72.  
  73.             Console.WriteLine("Submissions:");
  74.  
  75.             foreach (var item in dictCount.OrderByDescending(x => x.Value).ThenBy(x=>x.Key))
  76.             {
  77.                 Console.WriteLine($"{item.Key} - {item.Value}");
  78.             }
  79.  
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment