Advertisement
North_Point

4тапитоня

Aug 9th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.85 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Collections.Generic;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace Junk
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             Dictionary<string, Dictionary<string, int>> players = new Dictionary<string, Dictionary<string, int>>();
  14.  
  15.             string line;
  16.             while ("Ave Cesar" != (line = Console.ReadLine()))
  17.             {
  18.                 string[] tokens = line.Split(new[] { " -> " }, StringSplitOptions.RemoveEmptyEntries);
  19.  
  20.                 if (tokens.Length > 1)
  21.                 {
  22.                     string gladiator = tokens[0];
  23.                     string technique = tokens[1];
  24.                     int skill = int.Parse(tokens[2]);
  25.  
  26.                     if (!players.ContainsKey(gladiator))
  27.                     {
  28.                         players.Add(gladiator, new Dictionary<string, int>());
  29.                     }
  30.  
  31.                     if (!players[gladiator].ContainsKey(technique))
  32.                     {
  33.                         players[gladiator].Add(technique, skill);
  34.                     }
  35.                     else
  36.                     {
  37.                         int oldSkill = players[gladiator][technique];
  38.  
  39.                         if (skill > oldSkill)
  40.                         {
  41.                             players[gladiator][technique] = skill;
  42.                         }
  43.                     }
  44.                 }
  45.                 else
  46.                 {
  47.                     tokens = line.Split(new[] { " vs " }, StringSplitOptions.RemoveEmptyEntries);
  48.  
  49.                     string player1 = tokens[0];
  50.                     string player2 = tokens[1];
  51.  
  52.                     if (!players.ContainsKey(player1) || !players.ContainsKey(player2))
  53.                     {
  54.                         continue;
  55.                     }
  56.  
  57.                     Dictionary<string, int> player1Positions = players[player1];
  58.                     Dictionary<string, int> player2Positions = players[player2];
  59.  
  60.                     bool hasCommonRole = HasCommonRole(player1Positions, player2Positions);
  61.  
  62.                     if (hasCommonRole)
  63.                     {
  64.                         int player1TotalPoints = player1Positions.Values.Sum();
  65.                         int player2TotalPoints = player2Positions.Values.Sum();
  66.  
  67.                         if (player1TotalPoints > player2TotalPoints)
  68.                         {
  69.                             players.Remove(player2);
  70.                         }
  71.                         else
  72.                         {
  73.                             players.Remove(player1);
  74.                         }
  75.                     }
  76.                 }
  77.             }
  78.  
  79.             Dictionary<string, Dictionary<string, int>> sortedPlayers = players
  80.                 .OrderByDescending(p => p.Value.Values.Sum())
  81.                 .ThenBy(p => p.Key)
  82.                 .ToDictionary(x => x.Key, x => x.Value);
  83.  
  84.             foreach (var player in sortedPlayers)
  85.             {
  86.                 int points = player.Value.Values.Sum();
  87.                 Console.WriteLine($"{player.Key}: {points} skill");
  88.  
  89.                 var sortedRoles = player.Value
  90.                     .OrderByDescending(r => r.Value)
  91.                     .ThenBy(r => r.Key)
  92.                     .ToDictionary(x => x.Key, x => x.Value);
  93.  
  94.                 foreach (var role in sortedRoles)
  95.                 {
  96.                     Console.WriteLine($"- {role.Key} <!> {role.Value}");
  97.                 }
  98.             }
  99.         }
  100.  
  101.         private static bool HasCommonRole(Dictionary<string, int> player1, Dictionary<string, int> player2)
  102.         {
  103.             foreach (var role in player1)
  104.             {
  105.                 if (player2.ContainsKey(role.Key))
  106.                 {
  107.                     return true;
  108.                 }
  109.             }
  110.  
  111.             return false;
  112.         }
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement