kalitarix

MOBA challenger

Jun 27th, 2018
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace MOBAchallenger_04_18
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Dictionary<string, int> players = new Dictionary<string, int>();
  12.             Dictionary<string, Dictionary<string, int>> stats = new Dictionary<string, Dictionary<string, int>>();
  13.  
  14.             while (true)
  15.             {
  16.                 string input = Console.ReadLine();
  17.  
  18.                 if (input == "Season end")
  19.                 {
  20.                     break;
  21.                 }
  22.  
  23.                 string[] data = input.Split(new char[] { ' ', '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
  24.  
  25.                 if (input.Contains("->"))
  26.                 {
  27.  
  28.                     string player = data[0];
  29.                     string position = data[1];
  30.                     int skill = int.Parse(data[2]);
  31.  
  32.                     if (players.ContainsKey(player) == false)
  33.                     {
  34.                         players.Add(player, skill);
  35.                         stats.Add(player, new Dictionary<string, int>());
  36.                         stats[player].Add(position, skill);
  37.                     }
  38.  
  39.                     if (stats[player].ContainsKey(position) == false)
  40.                     {
  41.                         stats[player].Add(position, skill);
  42.                         players[player] += skill;
  43.                     }
  44.                     else if(stats[player][position] < skill)
  45.                     {
  46.                         stats[player][position] = skill;
  47.                         players[player] -= stats[player][position];
  48.                         players[player] += skill;
  49.                     }
  50.  
  51.                 }
  52.                 else
  53.                 {
  54.                     string firstPlayer = data[0];
  55.                     string secondPlayer = data[2];
  56.  
  57.                     if (players.ContainsKey(firstPlayer) && players.ContainsKey(secondPlayer))
  58.                     {
  59.                         bool haveCommonPosition = false;
  60.  
  61.                         foreach (string position in stats[firstPlayer].Keys)
  62.                         {
  63.                             foreach (string position2 in stats[secondPlayer].Keys)
  64.                             {
  65.                                 if (position == position2)
  66.                                 {
  67.                                     haveCommonPosition = true;
  68.                                     break;
  69.                                 }
  70.                             }
  71.  
  72.                             if (haveCommonPosition)
  73.                             {
  74.                                 break;
  75.                             }
  76.                         }
  77.  
  78.                         if (haveCommonPosition)
  79.                         {
  80.                             if (players[firstPlayer] > players[secondPlayer])
  81.                             {
  82.                                 players.Remove(secondPlayer);
  83.                                 stats.Remove(secondPlayer);
  84.                             }
  85.                             else if (players[secondPlayer] > players[firstPlayer])
  86.                             {
  87.                                 players.Remove(firstPlayer);
  88.                                 stats.Remove(firstPlayer);
  89.                             }
  90.                         }
  91.                     }
  92.                 }
  93.             }
  94.  
  95.             players = players.OrderByDescending(p => p.Value).ThenBy(p => p.Key).ToDictionary(p => p.Key, p => p.Value);
  96.  
  97.             foreach (var player in players)
  98.             {
  99.                 Console.WriteLine($"{player.Key}: {player.Value} skill");
  100.  
  101.                 stats[player.Key] = stats[player.Key].OrderByDescending(p => p.Value).ThenBy(p => p.Key).ToDictionary(p => p.Key, p => p.Value);
  102.  
  103.                 foreach (var position in stats[player.Key])
  104.                 {
  105.                     Console.WriteLine($"- {position.Key} <::> {position.Value}");
  106.                 }
  107.             }
  108.         }
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment