Advertisement
Chessmaster

SoftUni Exam Results

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