Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Text;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- namespace Junk
- {
- class Program
- {
- static void Main()
- {
- Dictionary<string, Dictionary<string, int>> players = new Dictionary<string, Dictionary<string, int>>();
- string line;
- while ("Ave Cesar" != (line = Console.ReadLine()))
- {
- string[] tokens = line.Split(new[] { " -> " }, StringSplitOptions.RemoveEmptyEntries);
- if (tokens.Length > 1)
- {
- string gladiator = tokens[0];
- string technique = tokens[1];
- int skill = int.Parse(tokens[2]);
- if (!players.ContainsKey(gladiator))
- {
- players.Add(gladiator, new Dictionary<string, int>());
- }
- if (!players[gladiator].ContainsKey(technique))
- {
- players[gladiator].Add(technique, skill);
- }
- else
- {
- int oldSkill = players[gladiator][technique];
- if (skill > oldSkill)
- {
- players[gladiator][technique] = skill;
- }
- }
- }
- else
- {
- tokens = line.Split(new[] { " vs " }, StringSplitOptions.RemoveEmptyEntries);
- string player1 = tokens[0];
- string player2 = tokens[1];
- if (!players.ContainsKey(player1) || !players.ContainsKey(player2))
- {
- continue;
- }
- Dictionary<string, int> player1Positions = players[player1];
- Dictionary<string, int> player2Positions = players[player2];
- bool hasCommonRole = HasCommonRole(player1Positions, player2Positions);
- if (hasCommonRole)
- {
- int player1TotalPoints = player1Positions.Values.Sum();
- int player2TotalPoints = player2Positions.Values.Sum();
- if (player1TotalPoints > player2TotalPoints)
- {
- players.Remove(player2);
- }
- else
- {
- players.Remove(player1);
- }
- }
- }
- }
- Dictionary<string, Dictionary<string, int>> sortedPlayers = players
- .OrderByDescending(p => p.Value.Values.Sum())
- .ThenBy(p => p.Key)
- .ToDictionary(x => x.Key, x => x.Value);
- foreach (var player in sortedPlayers)
- {
- int points = player.Value.Values.Sum();
- Console.WriteLine($"{player.Key}: {points} skill");
- var sortedRoles = player.Value
- .OrderByDescending(r => r.Value)
- .ThenBy(r => r.Key)
- .ToDictionary(x => x.Key, x => x.Value);
- foreach (var role in sortedRoles)
- {
- Console.WriteLine($"- {role.Key} <!> {role.Value}");
- }
- }
- }
- private static bool HasCommonRole(Dictionary<string, int> player1, Dictionary<string, int> player2)
- {
- foreach (var role in player1)
- {
- if (player2.ContainsKey(role.Key))
- {
- return true;
- }
- }
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement