Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace MOBAChallenger
- {
- class Program
- {
- static void Main(string[] args)
- {
- var playersWithPostionsAndSkills = new Dictionary<string, Dictionary<string, int>>();
- string input = string.Empty;
- while ((input = Console.ReadLine()) != "Season end")
- {
- if (input.Contains("->"))
- {
- string[] inputArray = input.Split(" -> ");
- string player = inputArray[0];
- string position = inputArray[1];
- int skill = int.Parse(inputArray[2]);
- if (playersWithPostionsAndSkills.ContainsKey(player) == false)
- {
- playersWithPostionsAndSkills[player] = new Dictionary<string, int>();
- playersWithPostionsAndSkills[player].Add(position, skill);
- }
- else if (playersWithPostionsAndSkills.ContainsKey(player) == true)
- {
- bool thePositionAlreadyExist = false;
- foreach (var kvp in playersWithPostionsAndSkills[player])
- {
- string currentPosition = kvp.Key;
- int currentSkill = kvp.Value;
- if (currentPosition == position)
- {
- thePositionAlreadyExist = true;
- if (currentSkill < skill)
- {
- playersWithPostionsAndSkills[player][position] = skill;
- break;
- }
- }
- }
- if (thePositionAlreadyExist == false)
- {
- playersWithPostionsAndSkills[player].Add(position, skill);
- }
- }
- }
- else if (input.Contains("vs"))
- {
- string[] inputArray = input.Split(" vs ");
- string firstPlayer = inputArray[0];
- string secondPlayer = inputArray[1];
- if (playersWithPostionsAndSkills.ContainsKey(firstPlayer) && playersWithPostionsAndSkills.ContainsKey(secondPlayer))
- {
- int totalSkillsFirstPlayer = playersWithPostionsAndSkills[firstPlayer].Values.Sum();
- int totalSkillsSecondPlayer = playersWithPostionsAndSkills[secondPlayer].Values.Sum();
- bool haveWinner = false;
- foreach (var kvp1 in playersWithPostionsAndSkills[firstPlayer])
- {
- string position1 = kvp1.Key;
- foreach (var kvp2 in playersWithPostionsAndSkills[secondPlayer])
- {
- string position2 = kvp2.Key;
- if (position1 == position2)
- {
- if (totalSkillsFirstPlayer > totalSkillsSecondPlayer)
- {
- playersWithPostionsAndSkills.Remove(secondPlayer);
- haveWinner = true;
- break;
- }
- else if (totalSkillsSecondPlayer > totalSkillsFirstPlayer)
- {
- playersWithPostionsAndSkills.Remove(firstPlayer);
- haveWinner = true;
- break;
- }
- }
- }
- if (haveWinner)
- {
- break;
- }
- }
- }
- }
- }
- PrintResult(playersWithPostionsAndSkills);
- }
- private static void PrintResult(Dictionary<string, Dictionary<string, int>> playersWithPostionsAndSkills)
- {
- foreach (var kvp in playersWithPostionsAndSkills.OrderByDescending(x => x.Value.Values.Sum()).ThenBy(x => x.Key))
- {
- string player = kvp.Key;
- int totalSkill = kvp.Value.Values.Sum();// how to sum values
- Console.WriteLine($"{player}: {totalSkill} skill");
- foreach (var kvp1 in playersWithPostionsAndSkills[player].OrderByDescending(x => x.Value).ThenBy(x => x.Key))
- {
- string position = kvp1.Key;
- int skill = kvp1.Value;
- Console.WriteLine($"- {position} <::> {skill}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement