Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace _04MOBAChallenger
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, Dictionary<string, int>> playerSkillPos = new Dictionary<string, Dictionary<string, int>>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "Season end")
- {
- break;
- }
- if (!input.Contains("vs"))
- {
- string[] tokens = input.Split(" -> ");
- string name = tokens[0];
- string position = tokens[1];
- int skill = int.Parse(tokens[2]);
- if (!playerSkillPos.ContainsKey(name))
- {
- playerSkillPos.Add(name, new Dictionary<string, int>());
- playerSkillPos[name].Add(position, skill);
- }
- else if (playerSkillPos.ContainsKey(name)==true && playerSkillPos[name].ContainsKey(position)==false)
- {
- playerSkillPos[name].Add(position, skill);
- }
- else if (playerSkillPos.ContainsKey(name) == true && playerSkillPos[name].ContainsKey(position) == true)
- {
- if (skill>playerSkillPos[name][position])
- {
- playerSkillPos[name][position] = skill;
- }
- }
- }
- else
- {
- string[] tokens = input.Split(" vs ");
- string player1Name = tokens[0];
- string player2Name = tokens[1];
- if (playerSkillPos.ContainsKey(player1Name) && playerSkillPos.ContainsKey(player2Name))
- {
- List<string> player1Positions = new List<string>();
- foreach (var kvp in playerSkillPos)
- {
- string playerName = kvp.Key;
- var positions = kvp.Value.Keys;
- if (playerName == player1Name)
- {
- player1Positions.AddRange(positions);
- }
- }
- int player1TotalPoints = playerSkillPos[player1Name].Values.Sum();
- int player2TotalPoints = playerSkillPos[player2Name].Values.Sum();
- List<string> player2Positions = new List<string>();
- foreach (var kvp in playerSkillPos)
- {
- string playerName = kvp.Key;
- var positions = kvp.Value.Keys;
- if (playerName == player2Name)
- {
- player2Positions.AddRange(positions);
- }
- }
- foreach (var item in player1Positions)
- {
- if (player2Positions.Any(x=>x == $"{item}"))
- {
- if (player1TotalPoints>player2TotalPoints)
- {
- playerSkillPos.Remove(player2Name);
- }
- else if (player1TotalPoints < player2TotalPoints)
- {
- playerSkillPos.Remove(player1Name);
- }
- }
- }
- }
- }
- }
- foreach (var kvp in playerSkillPos.OrderByDescending(x=>x.Value.Values.Sum()).ThenBy(x=>x.Key))
- {
- Console.WriteLine($"{kvp.Key}: {kvp.Value.Values.Sum()} skill");
- foreach (var kvpValue in kvp.Value.OrderByDescending(x=>x.Value).ThenBy(x=>x.Key))
- {
- Console.WriteLine($"- {kvpValue.Key} <::> {kvpValue.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement