joro_thexfiles

2. Judge

Jul 28th, 2019
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.44 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.             var dict = new Dictionary<string, Dictionary<string, int>>();
  12.  
  13.             var usersTotalPoint = new Dictionary<string, int>();
  14.  
  15.             while (true)
  16.             {
  17.                 string text = Console.ReadLine();
  18.  
  19.                 if (text == "no more time")
  20.                 {
  21.                     break;
  22.                 }
  23.                 else
  24.                 {
  25.                     string[] info = text
  26.                         .Split(" -> ");
  27.  
  28.                     string username = info[0];
  29.                     string contest = info[1];
  30.                     int points = int.Parse(info[2]);
  31.                     bool itMustSum = false;
  32.  
  33.                     if (!dict.ContainsKey(contest))
  34.                     {
  35.                         dict[contest] = new Dictionary<string, int>();
  36.                         dict[contest][username] = points;
  37.                         itMustSum = true;
  38.                     }
  39.                     else
  40.                     {
  41.                         if (!dict[contest].ContainsKey(username))
  42.                         {
  43.                             dict[contest][username] = points;
  44.                             itMustSum = true;
  45.                         }
  46.                         else
  47.                         {
  48.                             int currentPoints = dict[contest][username];
  49.  
  50.                             if (currentPoints < points)
  51.                             {
  52.                                 dict[contest][username] = points;
  53.                                 points = points - currentPoints; // Тук вадя от новите точки старите за да получа само разликата, която по-късно да добавя в usersTotalPoint
  54.                                 itMustSum = true;
  55.                             }
  56.                         }
  57.                     }
  58.  
  59.                     if (!usersTotalPoint.ContainsKey(username))
  60.                     {
  61.                         usersTotalPoint[username] = 0;
  62.                     }
  63.                     // Добавям точките в втория речник, само ако е изпълнено условието при горните проверки т.е. itMustSum е true
  64.                     if (itMustSum)
  65.                     {
  66.                         usersTotalPoint[username] += points;
  67.                     }
  68.  
  69.                 }
  70.             }
  71.  
  72.             foreach (var kvp in dict)
  73.             {
  74.                 Console.WriteLine($"{kvp.Key}: {kvp.Value.Count()} participants");
  75.  
  76.                 int counter = 1;
  77.  
  78.                 foreach (var item in kvp.Value
  79.                     .OrderByDescending(x => x.Value)
  80.                     .ThenBy(x => x.Key))
  81.                 {
  82.                     Console.WriteLine($"{counter}. {item.Key} <::> {item.Value}");
  83.                     counter++;
  84.                 }
  85.             }
  86.  
  87.             Console.WriteLine($"Individual standings:");
  88.  
  89.             int counterForUsers = 1;
  90.  
  91.             foreach (var kvp in usersTotalPoint
  92.                 .OrderByDescending(x => x.Value)
  93.                 .ThenBy(x => x.Key))
  94.             {
  95.                 Console.WriteLine($"{counterForUsers}. {kvp.Key} -> {kvp.Value}");
  96.                 counterForUsers++;
  97.             }
  98.  
  99.  
  100.         }
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment