TheBulgarianWolf

Judge

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