TheBulgarianWolf

Softuni Exam Results

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