kalitarix

Exam results

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