Advertisement
TeMePyT

Untitled

Jun 3rd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace MOBAChallenger
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var allPlayers = new SortedDictionary<string, SortedDictionary<string, int>>();
  12.  
  13.             List<string> input = Console.ReadLine().Split(' ').ToList();
  14.  
  15.             while (input[0] != "Season")
  16.             {
  17.                 if (input[1] == "vs")
  18.                 {
  19.                     string firstPlayer = input[0];
  20.                     string secondPlayer = input[2];
  21.  
  22.                     if (allPlayers.ContainsKey(firstPlayer) && allPlayers.ContainsKey(secondPlayer) && (firstPlayer != secondPlayer))
  23.                     {
  24.                         bool defeated = false;
  25.                         foreach (var position1 in allPlayers[firstPlayer])
  26.                         {
  27.                             foreach (var position2 in allPlayers[secondPlayer])
  28.                             {
  29.                                 if (position1.Key == position2.Key)
  30.                                 {
  31.                                     if (position1.Value > position2.Value)
  32.                                     {
  33.                                         allPlayers.Remove(secondPlayer);
  34.                                         defeated = true;
  35.                                         break;
  36.                                     }
  37.                                     else if (position2.Value > position1.Value)
  38.                                     {
  39.                                         allPlayers.Remove(firstPlayer);
  40.                                         defeated = true;
  41.                                         break;
  42.                                     }
  43.                                 }
  44.                             }
  45.                             if (defeated)
  46.                             {
  47.                                 break;
  48.                             }
  49.                         }
  50.                     }
  51.                 }
  52.                 else
  53.                 {
  54.                     string player = input[0];
  55.                     string position = input[2];
  56.                     int skill = int.Parse(input[4]);
  57.                     var temporary = new SortedDictionary<string, int>();
  58.                     if (!allPlayers.ContainsKey(player))
  59.                     {
  60.                         temporary.Add(position, skill);
  61.                         allPlayers.Add(player, temporary);
  62.                     }
  63.                     else
  64.                     {
  65.                         if (!allPlayers[player].ContainsKey(position))
  66.                         {
  67.                             allPlayers[player].Add(position, skill);
  68.                         }
  69.                         else
  70.                         {
  71.                             if (allPlayers[player][position] < skill)
  72.                             {
  73.                                 allPlayers[player][position] = skill;
  74.                             }
  75.  
  76.                         }
  77.                     }
  78.                 }
  79.                 input = Console.ReadLine().Split(' ').ToList();
  80.             }
  81.             int totalSkill = 0;
  82.             foreach (var item in allPlayers.OrderByDescending(x => x.Value.Values.Sum()).ThenBy(x => x.Key))
  83.             {
  84.                 totalSkill = item.Value.Values.Sum();
  85.                 Console.WriteLine($"{item.Key}: {totalSkill} skill");
  86.                 foreach (var pair in item.Value.OrderByDescending(x => x.Value))
  87.                 {
  88.                     Console.WriteLine($"- {pair.Key} <::> {pair.Value}");
  89.                 }
  90.             }
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement