TheBulgarianWolf

MOBA_Challenger

Mar 12th, 2021
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.81 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace MOBA_Challenger
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Console.WriteLine("Start entering: ");
  12.             string input;
  13.             Dictionary<string, Dictionary<string, int>> playersPool = new Dictionary<string, Dictionary<string, int>>();
  14.             while((input = Console.ReadLine()) != "Season end")
  15.             {
  16.                 string[] inputArr = input.Split(" ");
  17.                 if(inputArr[1] == "vs")
  18.                 {
  19.                     string playerOne = inputArr[0];
  20.                     string playerTwo = inputArr[2];
  21.                     if(playersPool.ContainsKey(playerOne) == true && playersPool.ContainsKey(playerTwo) == true)
  22.                     {
  23.                         foreach(var pos in playersPool[playerOne])
  24.                         {
  25.                             if (playersPool[playerTwo].ContainsKey(pos.Key))
  26.                             {
  27.                                 if(playersPool[playerOne].Values.Sum() < playersPool[playerTwo].Values.Sum())
  28.                                 {
  29.                                     playersPool.Remove(playerOne);
  30.                                 }
  31.                                 else if(playersPool[playerOne].Values.Sum() > playersPool[playerTwo].Values.Sum())
  32.                                 {
  33.                                     playersPool.Remove(playerTwo);
  34.                                 }
  35.                             }
  36.                         }
  37.                     }
  38.                 }
  39.                 else
  40.                 {
  41.                     string player = inputArr[0];
  42.                     string position = inputArr[2];
  43.                     int skill = int.Parse(inputArr[4]);
  44.                     if(playersPool.ContainsKey(player) == false)
  45.                     {
  46.                         playersPool.Add(player, new Dictionary<string, int>());
  47.                     }
  48.  
  49.                     if(playersPool[player].ContainsKey(position) == false)
  50.                     {
  51.                         playersPool[player].Add(position, 0);
  52.                     }
  53.  
  54.                     if(playersPool[player][position] < skill)
  55.                     {
  56.                         playersPool[player][position] = skill;
  57.                     }
  58.                 }
  59.                
  60.             }
  61.  
  62.             foreach (var player in playersPool.OrderByDescending(p => p.Value.Values.Sum()).ThenBy(n => n.Key))
  63.             {
  64.                 Console.WriteLine($"{player.Key}: {player.Value.Values.Sum()}skill.");
  65.                 foreach (var pos in player.Value.OrderByDescending(k => k.Value).ThenBy(v => v.Key)){
  66.                     Console.WriteLine($"- {pos.Key} <::> {pos.Value}");
  67.                 }
  68.             }
  69.         }
  70.     }
  71. }
  72.  
Add Comment
Please, Sign In to add comment