Advertisement
nikolapetkov824

Ranking

Dec 6th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Ranking
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Dictionary<string, string> map1 =
  12.                 new Dictionary<string, string>();
  13.             Dictionary<string, Dictionary<string,int>> map2 =
  14.                 new Dictionary<string, Dictionary<string, int>>();
  15.  
  16.             int totalPoints = 0;
  17.  
  18.             while (true)
  19.             {
  20.                 string input = Console.ReadLine();
  21.  
  22.                 if (input=="end of contests")
  23.                 {
  24.                     break;
  25.                 }
  26.  
  27.                 string[] array = input.Split(":");
  28.  
  29.                 string contest = array[0];
  30.                 string passwordForContest = array[1];
  31.  
  32.                 if (!map1.ContainsKey(contest))
  33.                 {
  34.                     map1.Add(contest, passwordForContest);
  35.                 }
  36.             }
  37.  
  38.             while (true)
  39.             {
  40.                 string input = Console.ReadLine();
  41.  
  42.                 if (input == "end of submissions")
  43.                 {
  44.                     break;
  45.                 }
  46.  
  47.                 string[] array = input.Split("=>");
  48.  
  49.                 string contest = array[0];
  50.                 string password = array[1];
  51.                 string username = array[2];
  52.                 int points = int.Parse(array[3]);
  53.  
  54.                 if (map1.ContainsKey(contest) && map1.ContainsValue(password))
  55.                 {
  56.                     if (!map2.ContainsKey(username))
  57.                     {
  58.                         map2.Add(username, new Dictionary<string, int>());
  59.  
  60.                         if (!map2[username].ContainsKey(contest))
  61.                         {
  62.                             map2[username].Add(contest, points);
  63.                         }
  64.                         else
  65.                         {
  66.                             if (points > map2[username][contest])
  67.                             {
  68.                                 map2[username][contest] = points;
  69.                             }
  70.                         }
  71.                     }
  72.                     else
  73.                     {
  74.                         if (!map2[username].ContainsKey(contest))
  75.                         {
  76.                             map2[username].Add(contest, points);
  77.                         }
  78.                         else
  79.                         {
  80.                             if (points > map2[username][contest])
  81.                             {
  82.                                 map2[username][contest] = points;
  83.                             }
  84.                         }
  85.                     }
  86.                 }
  87.             }
  88.  
  89.             foreach (var person in map2)
  90.             {
  91.                 foreach (var pointScore in person.Value)
  92.                 {
  93.                     totalPoints += pointScore.Value;
  94.                 }
  95.  
  96.                 Console.WriteLine($"Best candidate is {person.Key} with total {person.Value.Values.Sum()} points.");
  97.                 break;
  98.             }
  99.             Console.WriteLine("Ranking: ");
  100.             foreach (var user in map2.OrderBy(u=>u.Key))
  101.             {
  102.                 Console.WriteLine(user.Key);
  103.  
  104.                 foreach (var item in user.Value.OrderByDescending(p=>p.Value))
  105.                 {
  106.                     Console.WriteLine($"#  {item.Key} -> {item.Value}");
  107.                 }
  108.             }
  109.         }
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement