WindFell

Moba Challanger

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