Advertisement
Dimitar_Mitranov

Untitled

Nov 15th, 2018
496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.51 KB | None | 0 0
  1. namespace P16.Ranking
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     public class Ranking
  8.     {
  9.         public static void Main()
  10.         {
  11.             var contestsInformation = new Dictionary<string, string>();
  12.             while (true)
  13.             {
  14.                 var contestElements = Console.ReadLine().Split(':').ToList();
  15.                 if (contestElements[0] == "end of contests")
  16.                 {
  17.                     break;
  18.                 }
  19.                 else
  20.                 {
  21.                     var name = contestElements[0];
  22.                     var password = contestElements[1];
  23.  
  24.                     contestsInformation[name] = password;
  25.                 }
  26.             }
  27.  
  28.             var userInformation = new Dictionary<string, Dictionary<string, int>>();
  29.  
  30.             var bestCanditateName = string.Empty;
  31.             var memoryPoints = 0;
  32.             var bestCandidatePoints = 0;
  33.             while (true)
  34.             {
  35.                 var submissionElements = Console.ReadLine().Split("=>").ToList();
  36.                 if (submissionElements[0] == "end of submissions")
  37.                 {
  38.                     foreach (var kvp in userInformation)
  39.                     {
  40.                         foreach (var keyValuePair in kvp.Value)
  41.                         {
  42.                             bestCandidatePoints += keyValuePair.Value;
  43.                         }
  44.  
  45.                         if (bestCandidatePoints > memoryPoints)
  46.                         {
  47.                             memoryPoints = bestCandidatePoints;
  48.                             bestCanditateName = kvp.Key;
  49.                             bestCandidatePoints = 0;
  50.                         }
  51.                     }
  52.                     Console.WriteLine($"Best candidate {bestCanditateName} with total {memoryPoints}.");
  53.                     break;
  54.                 }
  55.                 else
  56.                 {
  57.                     var language = submissionElements[0];
  58.                     var password = submissionElements[1];
  59.                     var username = submissionElements[2];
  60.                     var points = int.Parse(submissionElements[3]);
  61.  
  62.                     if (contestsInformation.ContainsKey(language))
  63.                     {
  64.                         if (password == contestsInformation[language])
  65.                         {
  66.                             if (!userInformation.ContainsKey(username))
  67.                             {
  68.                                 userInformation[username] = new Dictionary<string, int>();
  69.                             }
  70.  
  71.                             if (!userInformation[username].ContainsKey(language))
  72.                             {
  73.                                 userInformation[username][language] = 0;
  74.                             }
  75.  
  76.                             if (points > userInformation[username][language])
  77.                             {
  78.                                 userInformation[username][language] = points;
  79.                             }
  80.                         }
  81.                     }
  82.                 }
  83.             }
  84.  
  85.  
  86.             var resultDictionary = userInformation.OrderBy(k => k.Key).ThenByDescending(k => );
  87.             foreach (var kvp in resultDictionary)
  88.             {
  89.                 Console.WriteLine($"{kvp.Key}");
  90.                 foreach (var keyValuePair in kvp.Value)
  91.                 {
  92.                     Console.WriteLine($"# {keyValuePair.Key}->{keyValuePair.Value}");
  93.                 }
  94.             }
  95.         }
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement