Advertisement
Guest User

softUniExamResults

a guest
Nov 15th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace softUniExamResults
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Dictionary<string, Students> examInformation = new Dictionary<string, Students>();
  12.             Dictionary<string, int> languages = new Dictionary<string, int>();
  13.             string command = Console.ReadLine();
  14.             while (command != "exam finished")
  15.             {
  16.                 string[] input = command.Split("-");
  17.                 string name = input[0];
  18.                 if (!command.Contains("banned"))
  19.                 {
  20.                     string language = input[1];
  21.                     int points = int.Parse(input[2]);
  22.                     if (!examInformation.ContainsKey(name))
  23.                     {
  24.                         examInformation.Add(name, new Students());
  25.                     }
  26.                     if (!languages.ContainsKey(language))
  27.                     {
  28.                         languages.Add(language, 0);
  29.                     }
  30.                     languages[language]++;
  31.                     if (!examInformation[name].Language.Contains(language))
  32.                     {
  33.                         examInformation[name].Language.Add(language);
  34.                         examInformation[name].Points.Add(points);
  35.                     }
  36.                     else
  37.                     {
  38.                         int index = examInformation[name].Language.FindIndex(x => x.Contains(language));
  39.                         if (examInformation[name].Language[index] == language && examInformation[name].Points[index] < points)
  40.                         {
  41.                             examInformation[name].Points[index] = points;
  42.                         }
  43.                     }
  44.                 }
  45.                 else
  46.                 {
  47.                     examInformation.Remove(name);
  48.                 }
  49.                 command = Console.ReadLine();
  50.             }
  51.             //examInformation = examInformation.OrderByDescending(x => x.Value.Points.Any()).ThenBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value); ;
  52.             Console.WriteLine("Results:");
  53.             foreach (var kvp in examInformation)
  54.             {
  55.                 Console.WriteLine($"{kvp.Key} | {string.Join($"\n{kvp.Key} | ", kvp.Value.Points)}");
  56.             }
  57.             languages = languages.OrderByDescending(x => x.Value).ThenBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
  58.             Console.WriteLine("Submissions:");
  59.             foreach (var kvp in languages)
  60.             {
  61.                 Console.WriteLine($"{kvp.Key} - {kvp.Value}");
  62.             }
  63.         }
  64.     }
  65.  
  66.     class Students
  67.     {
  68.         //public Dictionary<List<string>, List<int>> LanguageAndPoints { get; set; }
  69.         public List<string> Language { get; set; } = new List<string>();
  70.         public List<int> Points { get; set; } = new List<int>();
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement