Advertisement
Guest User

MOBA Challenger

a guest
Apr 25th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Linq;
  5.  
  6.  
  7. namespace Moba_Challenger
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.             Dictionary<string, Dictionary<string, int>> players = new Dictionary<string, Dictionary<string, int>>();
  15.  
  16.             while (input != "Season end")
  17.             {
  18.                 if (input.Contains("->"))
  19.                 {
  20.                     string[] playersInfo = input.Split(" -> ").ToArray();
  21.                     string playerName = playersInfo[0];
  22.                     string playerPosition = playersInfo[1];
  23.                     int playerSkill = int.Parse(playersInfo[2]);
  24.                     if (!players.ContainsKey(playerName))
  25.                     {
  26.                         players.Add(playerName, new Dictionary<string, int>());
  27.                         players[playerName].Add(playerPosition, playerSkill);
  28.                     }
  29.                     else
  30.                     {
  31.                         if (!players[playerName].ContainsKey(playerPosition))
  32.                         {
  33.                             players[playerName].Add(playerPosition, playerSkill);
  34.                         }
  35.                         else
  36.                         {
  37.                             if (players[playerName][playerPosition] < playerSkill)
  38.                             {
  39.                                 players[playerName][playerPosition] = playerSkill;
  40.                             }
  41.                         }
  42.                     }
  43.                 }
  44.                 else
  45.                 {
  46.                     string[] duelPlayers = input.Split(" vs ").ToArray();
  47.                     string firstPlayer = duelPlayers[0];
  48.                     string secondPlayer = duelPlayers[1];
  49.                     if (players.ContainsKey(firstPlayer) && players.ContainsKey(secondPlayer))
  50.                     {
  51.                         string currPosition = "";
  52.                         bool doesExist = false;
  53.                         foreach (var positionFirst in players[firstPlayer].Keys)
  54.                         {
  55.                             foreach (var positionSecond in players[secondPlayer].Keys)
  56.                             {
  57.                                 if (positionFirst.Equals(positionSecond))
  58.                                 {
  59.                                     currPosition = positionSecond;
  60.                                     doesExist = true;
  61.                                     break;
  62.                                 }
  63.                             }
  64.  
  65.                             if (doesExist == true)
  66.                             {
  67.                                 if (players[firstPlayer][currPosition] > players[secondPlayer][currPosition])
  68.                                 {
  69.                                     players.Remove(secondPlayer);
  70.                                 }
  71.                                 else if (players[firstPlayer][currPosition] < players[secondPlayer][currPosition])
  72.                                 {
  73.                                     players.Remove(firstPlayer);
  74.                                 }
  75.                                 break;
  76.                             }
  77.                         }
  78.                     }
  79.                 }
  80.                 input = Console.ReadLine();
  81.             }
  82.  
  83.             foreach (var winner in players.Keys.OrderByDescending(s => players[s].Values.Sum()).ThenBy(x => x))
  84.             {
  85.                 Console.WriteLine($"{winner}: {players[winner].Values.Sum()} skill");
  86.                 foreach (var pos in players[winner].Keys.OrderByDescending(x => players[winner][x]).ThenBy(y => y))
  87.                 {
  88.                     Console.WriteLine($"- {pos} <::> {players[winner][pos]}");
  89.                 }
  90.             }
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement