Advertisement
reking12

Untitled

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