Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Numerics;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace ConsoleApp3
- {
- class Program
- {
- static void Main(string[] args)
- {
- var players = new Dictionary<string, Dictionary<string, long>>();
- var playersTotal = new Dictionary<string, long>();
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "Season end") break;
- string[] inputArr = input.Split(" -> ", StringSplitOptions.RemoveEmptyEntries);
- if (inputArr.Length > 1) // INPUT
- {
- string playerNmae = inputArr[0];
- string position = inputArr[1];
- long skill = long.Parse(inputArr[2]);
- if (players.ContainsKey(playerNmae) == false)
- {
- players.Add(playerNmae, new Dictionary<string, long>());
- players[playerNmae].Add(position, skill);
- playersTotal.Add(playerNmae, skill);
- }
- else if (players[playerNmae].ContainsKey(position))
- {
- if (players[playerNmae][position] < skill)
- {
- playersTotal[playerNmae] += skill - players[playerNmae][position];
- players[playerNmae][position] = skill;
- }
- }
- else
- {
- players[playerNmae].Add(position, skill);
- playersTotal[playerNmae] += skill;
- }
- }
- else // BATTLE
- {
- string[] inputArr1 = input.Split(" vs ");
- string player1 = inputArr1[0];
- string player2 = inputArr1[1];
- if (players.ContainsKey(player1) && players.ContainsKey(player2))
- {
- foreach (var kvplayer1 in players[player1])
- {
- foreach (var kvplaer2 in players[player2])
- {
- if (kvplayer1.Key == kvplaer2.Key)
- {
- if (players[player1].Sum(x => x.Value) > players[player2].Sum(x => x.Value))
- {
- players.Remove(player2);
- playersTotal.Remove(player2);
- break;
- }
- else if (players[player1].Sum(x => x.Value) < players[player2].Sum(x => x.Value))
- {
- players.Remove(player1);
- playersTotal.Remove(player1);
- break;
- }
- }
- }
- }
- }
- }
- }
- // OUTPUT
- foreach (var kvp in playersTotal.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
- {
- Console.WriteLine($"{kvp.Key}: {kvp.Value} skill");
- foreach (var pos in players[kvp.Key].OrderByDescending(x => x.Value).ThenBy(x => x.Key))
- {
- Console.WriteLine($"- {pos.Key} <::> {pos.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment