anizko

02. Judge

Jul 12th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _02._Judge
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Dictionary<string, Dictionary<string, int>> dict = new Dictionary<string, Dictionary<string, int>>();
  13.             Dictionary<string, int> dictMax = new Dictionary<string, int>();
  14.             string comand = Console.ReadLine();
  15.  
  16.             while (comand != "no more time")
  17.             {
  18.                 string[] info = comand.Split("->");
  19.                 string name = info[0];
  20.                 string contest = info[1];
  21.                 int poits = int.Parse(info[2]);
  22.  
  23.                 if (!dict.ContainsKey(contest))
  24.                 {
  25.                     dict[contest] = new Dictionary<string, int>();
  26.                 }
  27.                 if (!dict[contest].ContainsKey(name))
  28.                 {
  29.                     dict[contest][name] = 0;
  30.                 }
  31.  
  32.                 if (dict[contest][name] < poits)
  33.                 {
  34.                     dict[contest][name] = poits;
  35.                 }
  36.  
  37.                 comand = Console.ReadLine();
  38.             }
  39.  
  40.             foreach (var contest in dict)
  41.             {
  42.                 Console.WriteLine($"{contest.Key}: {contest.Value.Count} participants");
  43.                 int count = 1;
  44.  
  45.                 foreach (var item in contest.Value.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  46.                 {
  47.                     Console.WriteLine($"{count}. {item.Key}<::> {item.Value}");
  48.                     count++;
  49.                 }
  50.             }
  51.             Console.WriteLine($"Individual standings:");
  52.  
  53.             foreach (var item in dict)
  54.             {
  55.                 foreach (var name in item.Value)
  56.                 {
  57.                     if (!dictMax.ContainsKey(name.Key))
  58.                     {
  59.                         dictMax[name.Key] = 0;
  60.                     }
  61.                     dictMax[name.Key] += name.Value;
  62.                 }
  63.             }
  64.             int countResult = 1;
  65.  
  66.             foreach (var item in dictMax.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  67.             {
  68.                 Console.WriteLine($"{countResult}. {item.Key}-> {item.Value}");
  69.                 countResult++;
  70.             }
  71.  
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment