Advertisement
reking12

Untitled

Apr 9th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P01Ranking
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var contestAndPassword = new Dictionary<string, string>();
  12.             var result = new Dictionary<string, Dictionary<string, double>>();
  13.  
  14.             while (true)
  15.             {
  16.                 string end = Console.ReadLine();
  17.                 if (end == "end of contests")
  18.                 {
  19.                     break;
  20.                 }
  21.                 List<string> command = end.Split(":").ToList();
  22.                 string contest = command[0];
  23.                 string password = command[1];
  24.                 if (!contestAndPassword.ContainsKey(contest))
  25.                 {
  26.                     contestAndPassword[contest] = password;
  27.                 }
  28.             }
  29.             while (true)
  30.             {
  31.                 string end = Console.ReadLine();
  32.                 if (end == "end of submissions")
  33.                 {
  34.                     break;
  35.                 }
  36.                 List<string> command = end.Split("=>").ToList();
  37.                 string contest = command[0];
  38.                 string password = command[1];
  39.                 string username = command[2];
  40.                 double points = double.Parse(command[3]);
  41.                 if (contestAndPassword.ContainsKey(contest) && contestAndPassword.ContainsValue(password))
  42.                 {
  43.                     if (!result.ContainsKey(username))
  44.                     {
  45.                         result[username] = new Dictionary<string, double>();
  46.                         result[username][contest] = points;
  47.                     }
  48.                     else if (result[username].ContainsKey(contest))
  49.                     {
  50.                         if (result[username][contest] < points)
  51.                         {
  52.                             result[username][contest] = points;
  53.                         }
  54.                     }
  55.                     else
  56.                     {
  57.                         result[username][contest] = points;
  58.                     }
  59.                 }
  60.             }
  61.             double max = 0;
  62.             string name = "";
  63.             foreach (var item in result)
  64.             {
  65.                 double currentMax = item.Value.Values.Sum();
  66.                 if (currentMax > max)
  67.                 {
  68.                     max = currentMax;
  69.                     name = item.Key;
  70.                 }
  71.             }
  72.             Console.WriteLine($"Best candidate is {name} with total {max} points.");
  73.             Console.WriteLine("Ranking: ");
  74.             foreach (var item in result.OrderBy(x => x.Key))
  75.             {
  76.                 Console.WriteLine(item.Key);
  77.                 foreach (var item1 in item.Value.OrderByDescending(x => x.Value))
  78.                 {
  79.                     Console.WriteLine($"#  {item1.Key} -> {item1.Value}");
  80.                 }
  81.             }
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement