Guest User

Untitled

a guest
Aug 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 KB | None | 0 0
  1. namespace Exercise
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     public class Startup
  8.     {
  9.         public static void Main()
  10.         {
  11.             string input = Console.ReadLine();
  12.             var namesAndScores = new Dictionary<string, int>();
  13.             var languageAndCount = new Dictionary<string, int>();
  14.  
  15.             while (input != "exam finished")
  16.             {
  17.                 List<string> lines = input
  18.                     .Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries)
  19.                     .ToList();
  20.  
  21.                 string name = lines[0];
  22.                 string language = lines[1];
  23.  
  24.                 if (lines[1] != "banned")
  25.                 {
  26.                     int score = int.Parse(lines[2]);
  27.  
  28.                     if (!namesAndScores.ContainsKey(name))
  29.                     {
  30.                         namesAndScores[name] = score ;
  31.                     }
  32.                     else
  33.                     {
  34.                         int oldScore = namesAndScores[name];
  35.                         namesAndScores[name] = Math.Max(oldScore, score);
  36.                     }
  37.  
  38.                     if (!languageAndCount.ContainsKey(language))
  39.                     {
  40.                         languageAndCount[language] = 1;
  41.                     }
  42.                     else
  43.                     {
  44.                         languageAndCount[language] ++;
  45.                     }
  46.                 }
  47.                 else
  48.                 {
  49.                     namesAndScores.Remove(name);
  50.                 }
  51.  
  52.                 input = Console.ReadLine();
  53.             }
  54.             Console.WriteLine("Results:");
  55.  
  56.             foreach (var kvp in namesAndScores
  57.                 .OrderBy(x => x.Key)
  58.                 .OrderByDescending(x => x.Value))
  59.             {
  60.                 Console.WriteLine($"{kvp.Key} | {kvp.Value}");
  61.             }
  62.             Console.WriteLine("Submissions:");
  63.  
  64.             foreach (var kvp in languageAndCount
  65.                 .OrderBy(x => x.Key))
  66.             {
  67.                 Console.WriteLine($"{kvp.Key} - {kvp.Value}");
  68.             }
  69.         }
  70.     }
  71. }
Add Comment
Please, Sign In to add comment