Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace MOBAchallenger_04_18
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, int> players = new Dictionary<string, int>();
- Dictionary<string, Dictionary<string, int>> stats = new Dictionary<string, Dictionary<string, int>>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "Season end")
- {
- break;
- }
- string[] data = input.Split(new char[] { ' ', '-', '>' }, StringSplitOptions.RemoveEmptyEntries);
- if (input.Contains("->"))
- {
- string player = data[0];
- string position = data[1];
- int skill = int.Parse(data[2]);
- if (players.ContainsKey(player) == false)
- {
- players.Add(player, skill);
- stats.Add(player, new Dictionary<string, int>());
- stats[player].Add(position, skill);
- }
- if (stats[player].ContainsKey(position) == false)
- {
- stats[player].Add(position, skill);
- players[player] += skill;
- }
- else if(stats[player][position] < skill)
- {
- stats[player][position] = skill;
- players[player] -= stats[player][position];
- players[player] += skill;
- }
- }
- else
- {
- string firstPlayer = data[0];
- string secondPlayer = data[2];
- if (players.ContainsKey(firstPlayer) && players.ContainsKey(secondPlayer))
- {
- bool haveCommonPosition = false;
- foreach (string position in stats[firstPlayer].Keys)
- {
- foreach (string position2 in stats[secondPlayer].Keys)
- {
- if (position == position2)
- {
- haveCommonPosition = true;
- break;
- }
- }
- if (haveCommonPosition)
- {
- break;
- }
- }
- if (haveCommonPosition)
- {
- if (players[firstPlayer] > players[secondPlayer])
- {
- players.Remove(secondPlayer);
- stats.Remove(secondPlayer);
- }
- else if (players[secondPlayer] > players[firstPlayer])
- {
- players.Remove(firstPlayer);
- stats.Remove(firstPlayer);
- }
- }
- }
- }
- }
- players = players.OrderByDescending(p => p.Value).ThenBy(p => p.Key).ToDictionary(p => p.Key, p => p.Value);
- foreach (var player in players)
- {
- Console.WriteLine($"{player.Key}: {player.Value} skill");
- stats[player.Key] = stats[player.Key].OrderByDescending(p => p.Value).ThenBy(p => p.Key).ToDictionary(p => p.Key, p => p.Value);
- foreach (var position in stats[player.Key])
- {
- Console.WriteLine($"- {position.Key} <::> {position.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment