Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Moba_Challenger
- {
- class Program
- {
- static void Main(string[] args)
- {
- string playerInfo = string.Empty;
- Dictionary<string, Dictionary<string, int>> playersDatabase = new Dictionary<string, Dictionary<string, int>>();
- while ((playerInfo = Console.ReadLine()) != "Season end")
- {
- string[] splitPlayerInfo = playerInfo.Split(" ", StringSplitOptions.RemoveEmptyEntries).ToArray();
- if ((splitPlayerInfo.Length > 3) && (splitPlayerInfo.Contains("->")))
- {
- string playerName = splitPlayerInfo[0];
- string playerPosition = splitPlayerInfo[2];
- int playerSkill = int.Parse(splitPlayerInfo[4]);
- if (playersDatabase.ContainsKey(playerName) == false)
- {
- playersDatabase.Add(playerName, new Dictionary<string, int>());
- playersDatabase[playerName].Add(playerPosition, playerSkill);
- }
- else if (playersDatabase[playerName].ContainsKey(playerPosition) == false)
- {
- playersDatabase[playerName].Add(playerPosition, playerSkill);
- }
- else
- {
- int oldSkillValue = playersDatabase[playerName][playerPosition];
- if (playerSkill > oldSkillValue)
- {
- playersDatabase[playerName][playerPosition] = playerSkill;
- }
- }
- }
- else if((splitPlayerInfo.Length == 3) && (splitPlayerInfo.Contains("vs")))
- {
- string firstDuelist = splitPlayerInfo[0];
- string secondDuelist = splitPlayerInfo[2];
- if(playersDatabase.ContainsKey(firstDuelist) && playersDatabase.ContainsKey(secondDuelist))
- {
- foreach (var position in playersDatabase[firstDuelist])
- {
- if (playersDatabase[secondDuelist].ContainsKey(position.Key))
- {
- int firstDuelistSkill = playersDatabase[firstDuelist][position.Key];
- int secondDuelistSkill = playersDatabase[secondDuelist][position.Key];
- playersDatabase.Remove(firstDuelistSkill > secondDuelistSkill ? secondDuelist : firstDuelist);
- }
- }
- }
- }
- }
- foreach (var player in playersDatabase.OrderByDescending(x => x.Value.Select(y => y.Value).Sum()).ThenBy(z => z.Key))
- {
- Console.WriteLine($"{player.Key}: {player.Value.Values.Sum()} skill");
- foreach (var positionAndSkill in playersDatabase[player.Key].OrderByDescending(x => x.Value).ThenBy(y => y.Key))
- {
- Console.WriteLine($"- {positionAndSkill.Key} <::> {positionAndSkill.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement