Advertisement
Kristina_Ivanova

Untitled

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