Guest User

Judge

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