Advertisement
silvana1303

softuni exam results

Jul 20th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace mid_exam
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var command = Console.ReadLine().Split('-').ToArray();
  12.  
  13.             var results = new Dictionary<string, int>();
  14.             var submissions = new Dictionary<string, int>();
  15.  
  16.  
  17.             while (command[0] != "exam finished")
  18.             {
  19.                 if (results.ContainsKey(command[0]) && command[1] != "banned")
  20.                 {
  21.                     if (int.Parse(command[2]) > results[command[0]])
  22.                     {
  23.                         results[command[0]] = int.Parse(command[2]);
  24.                     }
  25.                 }
  26.                 if ((!results.ContainsKey(command[0]) && command[1] != "banned"))
  27.                 {
  28.                     results[command[0]] = int.Parse(command[2]);
  29.                 }
  30.  
  31.                 if (submissions.ContainsKey(command[1]))
  32.                 {
  33.                     submissions[command[1]]++;
  34.                 }
  35.                 else
  36.                 {
  37.                     submissions[command[1]] = 1;
  38.                 }
  39.  
  40.                 if (command[1] == "banned")
  41.                 {
  42.                     results.Remove(command[0]);
  43.                     submissions.Remove(command[1]);
  44.                 }
  45.  
  46.                 command = Console.ReadLine().Split('-').ToArray();
  47.             }
  48.  
  49.             Console.WriteLine("Results:");
  50.  
  51.             foreach (var item in results.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  52.             {
  53.                 Console.WriteLine($"{item.Key} | {item.Value}");
  54.             }
  55.  
  56.             Console.WriteLine("Submissions:");
  57.  
  58.             foreach (var item in submissions.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  59.             {
  60.                 Console.WriteLine($"{item.Key} - {item.Value}");
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement