Advertisement
miroLLL

MOBA-CHALLENGER

Jun 7th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Moba_Challenger
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string playerInfo = string.Empty;
  12.             Dictionary<string, Dictionary<string, int>> playersDatabase = new Dictionary<string, Dictionary<string, int>>();
  13.  
  14.             while ((playerInfo = Console.ReadLine()) != "Season end")
  15.             {
  16.                 string[] splitPlayerInfo = playerInfo.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
  17.                
  18.                 if ((splitPlayerInfo.Length > 3) && (splitPlayerInfo.Contains("->")))
  19.                 {
  20.                     string playerName = splitPlayerInfo[0];
  21.                     string playerPosition = splitPlayerInfo[2];
  22.                     int playerSkill = int.Parse(splitPlayerInfo[4]);
  23.  
  24.                     if (playersDatabase.ContainsKey(playerName) == false)
  25.                     {
  26.                         playersDatabase.Add(playerName, new Dictionary<string, int>());
  27.                         playersDatabase[playerName].Add(playerPosition, playerSkill);
  28.                     }
  29.                     else if (playersDatabase[playerName].ContainsKey(playerPosition) == false)
  30.                     {
  31.                         playersDatabase[playerName].Add(playerPosition, playerSkill);
  32.                     }
  33.                     else
  34.                     {
  35.                         int oldSkillValue = playersDatabase[playerName][playerPosition];
  36.  
  37.                         if (playerSkill > oldSkillValue)
  38.                         {
  39.                             playersDatabase[playerName][playerPosition] = playerSkill;
  40.                         }
  41.                     }
  42.                 }
  43.                 else if((splitPlayerInfo.Length == 3) && (splitPlayerInfo.Contains("vs")))
  44.                 {
  45.                     string firstDuelist = splitPlayerInfo[0];
  46.                     string secondDuelist = splitPlayerInfo[2];
  47.  
  48.                     if(playersDatabase.ContainsKey(firstDuelist) && playersDatabase.ContainsKey(secondDuelist))
  49.                     {
  50.                         foreach (var position in playersDatabase[firstDuelist])
  51.                         {
  52.                             if (playersDatabase[secondDuelist].ContainsKey(position.Key))
  53.                             {
  54.                                 int firstDuelistSkill = playersDatabase[firstDuelist][position.Key];
  55.                                 int secondDuelistSkill = playersDatabase[secondDuelist][position.Key];
  56.  
  57.                                 playersDatabase.Remove(firstDuelistSkill > secondDuelistSkill ? secondDuelist : firstDuelist);
  58.                             }
  59.                         }
  60.                     }
  61.                 }
  62.             }
  63.  
  64.             foreach (var player in playersDatabase.OrderByDescending(x => x.Value.Select(y => y.Value).Sum()).ThenBy(z => z.Key))
  65.             {
  66.                 Console.WriteLine($"{player.Key}: {player.Value.Values.Sum()} skill");
  67.  
  68.                 foreach (var positionAndSkill in playersDatabase[player.Key].OrderByDescending(x => x.Value).ThenBy(y => y.Key))
  69.                 {
  70.                     Console.WriteLine($"- {positionAndSkill.Key} <::> {positionAndSkill.Value}");
  71.                 }
  72.             }
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement