joro_thexfiles

3. MOBA Challenger

Jul 28th, 2019
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _3._MOBA_Challenger
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var players = new Dictionary<string, Dictionary<string, int>>();
  12.             var levels = new Dictionary<string, Dictionary<string, int>>();
  13.  
  14.             while (true)
  15.             {
  16.                 string text = Console.ReadLine();
  17.  
  18.                 if (text == "Season end")
  19.                 {
  20.                     break;
  21.                 }
  22.                 else
  23.                 {
  24.                     if (text.Contains(" -> "))
  25.                     {
  26.                         string[] info = text
  27.                             .Split(" -> ");
  28.  
  29.                         string name = info[0];
  30.                         string position = info[1];
  31.                         int points = int.Parse(info[2]);
  32.  
  33.                         if (!players.ContainsKey(name))
  34.                         {
  35.                             players[name] = new Dictionary<string, int>();
  36.                             players[name][position] = points;
  37.                         }
  38.                         else
  39.                         {
  40.                             if (!players[name].ContainsKey(position))
  41.                             {
  42.                                 players[name][position] = points;
  43.                             }
  44.                             else
  45.                             {
  46.                                 int currentPoints = players[name][position];
  47.  
  48.                                 if (currentPoints < points)
  49.                                 {
  50.                                     players[name][position] = points;
  51.                                 }
  52.                             }
  53.                         }
  54.  
  55.                         if (!levels.ContainsKey(position))
  56.                         {
  57.                             levels[position] = new Dictionary<string, int>();
  58.                             levels[position][name] = points;
  59.                         }
  60.                         else
  61.                         {
  62.                             if (!levels[position].ContainsKey(name))
  63.                             {
  64.                                 levels[position][name] = points;
  65.                             }
  66.                             else
  67.                             {
  68.                                 int currentPoints = levels[position][name];
  69.  
  70.                                 if (currentPoints < points)
  71.                                 {
  72.                                     levels[position][name] = points;
  73.                                 }
  74.                             }
  75.                         }
  76.                     }
  77.                     else if (text.Contains(" vs "))
  78.                     {
  79.                         string[] input = text
  80.                             .Split(" vs ");
  81.  
  82.                         string player1 = input[0];
  83.                         string player2 = input[1];
  84.  
  85.                         foreach (var kvp in levels)
  86.                         {
  87.                             if (kvp.Value.ContainsKey(player1) && kvp.Value.ContainsKey(player2))
  88.                             {
  89.                                 int pointsOfPlayer1 = levels[kvp.Key][player1];
  90.                                 int pointsOfPlayer2 = levels[kvp.Key][player2];
  91.  
  92.                                 if (pointsOfPlayer1 > pointsOfPlayer2)
  93.                                 {
  94.                                     players[player2].Remove(kvp.Key);
  95.                                 }
  96.                                 else if (pointsOfPlayer1 < pointsOfPlayer2)
  97.                                 {
  98.                                     players[player1].Remove(kvp.Key);
  99.                                 }
  100.                             }
  101.                         }
  102.                     }
  103.                 }
  104.             }
  105.  
  106.             foreach (var item in players
  107.                 .OrderByDescending(x => x.Value.Sum(y => y.Value))
  108.                 .ThenBy(y => y.Key))
  109.             {
  110.                 if (item.Value.Count !=0)
  111.                 {
  112.                 Console.WriteLine($"{item.Key}: {item.Value.Sum(y => y.Value)} skill");
  113.                 }
  114.  
  115.                 foreach (var kvp in item.Value
  116.                     .Where(z => z.Value > 0)
  117.                     .OrderByDescending(x => x.Value)
  118.                     .ThenBy(y => y.Key))
  119.                 {
  120.                     Console.WriteLine($"- {kvp.Key} <::> {kvp.Value}");
  121.                 }
  122.             }
  123.         }
  124.     }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment