Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _3._MOBA_Challenger
- {
- class Program
- {
- static void Main()
- {
- Dictionary<string, Dictionary<string, int>> players = new Dictionary<string, Dictionary<string, int>>();
- string command = Console.ReadLine();
- while (command != "Season end")
- {
- string[] currentCommand = command.Split(new Char[] { ' ', '-', '>' },
- StringSplitOptions.RemoveEmptyEntries);
- string commandOne = currentCommand[0]; // playerName
- string commandTwo = currentCommand[1]; //playerPosition
- string commandThree = currentCommand[2]; //playerSkill
- bool isItDemoted = false;
- if (commandTwo == "vs")
- {
- if (players.ContainsKey(commandOne) && players.ContainsKey(commandThree))
- {
- foreach (var player in players[commandOne])
- {
- foreach (var position in players[commandThree])
- {
- if (player.Key == position.Key)
- {
- if (players[commandOne].Values.Sum() > players[commandThree].Values.Sum())
- {
- players.Remove(commandThree);
- isItDemoted = true;
- }
- else if (players[commandOne].Values.Sum() < players[commandThree].Values.Sum())
- {
- players.Remove(commandOne);
- isItDemoted = true;
- }
- else if (players[commandOne].Values.Sum() == players[commandThree].Values.Sum())
- {
- isItDemoted = true;
- }
- }
- }
- if (isItDemoted)
- {
- break;
- }
- }
- }
- command = Console.ReadLine();
- continue;
- }
- // Declaring the players AND ONLY IF their skill is increased we increase it!!
- if (!players.ContainsKey(commandOne))
- {
- players[commandOne] = new Dictionary<string, int>();
- players[commandOne].Add(commandTwo, int.Parse(commandThree));
- command = Console.ReadLine();
- continue;
- }
- else if (players.ContainsKey(commandOne))
- {
- if (!players[commandOne].ContainsKey(commandTwo))
- {
- players[commandOne].Add(commandTwo, int.Parse(commandThree));
- }
- else if (players.ContainsKey(commandOne) && players[commandOne][commandTwo] < int.Parse(commandThree))
- {
- players[commandOne][commandTwo] = int.Parse(commandThree);
- }
- }
- command = Console.ReadLine();
- }
- // Converting the Print by descending
- // First is the main Dicitonary
- // Then in the foreach loop is the nested Dictionary
- players = players
- .OrderByDescending(x => x.Value.Values.Sum())
- .ThenBy(x => x.Key)
- .ToDictionary(x => x.Key, x => x.Value);
- foreach (var kvp in players)
- {
- string name = kvp.Key;
- Dictionary<string, int> positionAndSkill = kvp.Value;
- positionAndSkill = positionAndSkill
- .OrderByDescending(x => x.Value)
- .ThenBy(x => x.Value)
- .ToDictionary(x => x.Key, x => x.Value);
- Console.WriteLine($"{name}: {positionAndSkill.Values.Sum()} skill");
- foreach (var kvp2 in positionAndSkill)
- {
- string position = kvp2.Key;
- int skill = kvp2.Value;
- Console.WriteLine($"- {position} <::> {skill}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment