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(string[] args)
- {
- var players = new Dictionary<string, Dictionary<string, int>>();
- var levels = new Dictionary<string, Dictionary<string, int>>();
- while (true)
- {
- string text = Console.ReadLine();
- if (text == "Season end")
- {
- break;
- }
- else
- {
- if (text.Contains(" -> "))
- {
- string[] info = text
- .Split(" -> ");
- string name = info[0];
- string position = info[1];
- int points = int.Parse(info[2]);
- if (!players.ContainsKey(name))
- {
- players[name] = new Dictionary<string, int>();
- players[name][position] = points;
- }
- else
- {
- if (!players[name].ContainsKey(position))
- {
- players[name][position] = points;
- }
- else
- {
- int currentPoints = players[name][position];
- if (currentPoints < points)
- {
- players[name][position] = points;
- }
- }
- }
- if (!levels.ContainsKey(position))
- {
- levels[position] = new Dictionary<string, int>();
- levels[position][name] = points;
- }
- else
- {
- if (!levels[position].ContainsKey(name))
- {
- levels[position][name] = points;
- }
- else
- {
- int currentPoints = levels[position][name];
- if (currentPoints < points)
- {
- levels[position][name] = points;
- }
- }
- }
- }
- else if (text.Contains(" vs "))
- {
- string[] input = text
- .Split(" vs ");
- string player1 = input[0];
- string player2 = input[1];
- foreach (var kvp in levels)
- {
- if (kvp.Value.ContainsKey(player1) && kvp.Value.ContainsKey(player2))
- {
- int pointsOfPlayer1 = levels[kvp.Key][player1];
- int pointsOfPlayer2 = levels[kvp.Key][player2];
- if (pointsOfPlayer1 > pointsOfPlayer2)
- {
- players[player2].Remove(kvp.Key);
- }
- else if (pointsOfPlayer1 < pointsOfPlayer2)
- {
- players[player1].Remove(kvp.Key);
- }
- }
- }
- }
- }
- }
- foreach (var item in players
- .OrderByDescending(x => x.Value.Sum(y => y.Value))
- .ThenBy(y => y.Key))
- {
- if (item.Value.Count !=0)
- {
- Console.WriteLine($"{item.Key}: {item.Value.Sum(y => y.Value)} skill");
- }
- foreach (var kvp in item.Value
- .Where(z => z.Value > 0)
- .OrderByDescending(x => x.Value)
- .ThenBy(y => y.Key))
- {
- Console.WriteLine($"- {kvp.Key} <::> {kvp.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment