Advertisement
Spocoman

02. Judge

Apr 9th, 2023 (edited)
721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace Judge
  6. {
  7.     class Program
  8.     {
  9.         public static void Main()
  10.         {
  11.             var contests = new Dictionary<string, Dictionary<string, int>>();
  12.             var individualStanding = new Dictionary<string, int>();
  13.  
  14.             string command;
  15.  
  16.             while ((command = Console.ReadLine()) != "no more time")
  17.             {
  18.                 var current = command.Split(" -> ");
  19.                 string user = current[0];
  20.                 string contest = current[1];
  21.                 int points = int.Parse(current[2]);
  22.  
  23.                 if (!contests.ContainsKey(contest))
  24.                 {
  25.                     contests.Add(contest, new Dictionary<string, int>());
  26.                 }
  27.  
  28.                 if (!contests[contest].ContainsKey(user))
  29.                 {
  30.                     contests[contest].Add(user, points);
  31.                 }
  32.  
  33.                 if (contests[contest][user] < points)
  34.                 {
  35.                     contests[contest][user] = points;
  36.                 }
  37.             }
  38.  
  39.             foreach (var contest in contests)
  40.             {
  41.                 int index = 1;
  42.                 Console.WriteLine($"{contest.Key}: {contest.Value.Count} participants");
  43.                 foreach (var user in contest.Value.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  44.                 {
  45.                     Console.WriteLine($"{index}. {user.Key} <::> {user.Value}");
  46.  
  47.                     if (!individualStanding.ContainsKey(user.Key))
  48.                     {
  49.                         individualStanding.Add(user.Key, 0);
  50.                     }
  51.  
  52.                     individualStanding[user.Key] += user.Value;
  53.                     index++;
  54.                 }
  55.             }
  56.  
  57.             int position = 1;
  58.             Console.WriteLine("Individual standings:");
  59.             foreach (var user in individualStanding.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  60.             {
  61.                 Console.WriteLine($"{position}. {user.Key} -> {user.Value}");
  62.                 position++;
  63.             }
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement