Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace WormsWorldParty
- {
- public class WormsWorldParty
- {
- public static void Main()
- {
- var input = Console.ReadLine();
- Dictionary<string, Dictionary<string, long>> rank = new Dictionary<string, Dictionary<string, long>>();
- while (input!= "quit")
- {
- var inputParams = input.Split(new[] { " -> " }, StringSplitOptions.RemoveEmptyEntries).ToList();
- var wormName = inputParams[0];
- var teamName = inputParams[1];
- var wormScore = long.Parse(inputParams[2]);
- if (!rank.ContainsKey(teamName))
- {
- rank[teamName] = new Dictionary<string, long>();
- }
- if (PlayerExist(rank, wormName) == true)
- {
- input = Console.ReadLine();
- continue;
- }
- if (!rank[teamName].ContainsKey(wormName))
- {
- rank[teamName][wormName] = 0;
- }
- rank[teamName][wormName] = wormScore;
- input = Console.ReadLine();
- }
- var orderedRank = rank.OrderByDescending(x => x.Value.Values.Sum())
- .ThenByDescending(x => x.Value.Values.Sum() / x.Value.Keys.Count)
- .ToDictionary(x=> x.Key, x=> x.Value);
- var counter = 1;
- foreach (var team in orderedRank)
- {
- Console.WriteLine(counter+". " +"Team: "+ team.Key + " - " + team.Value.Values.Sum());
- foreach (var player in team.Value.OrderByDescending(x => x.Value).ToList())
- {
- Console.WriteLine("###" + player.Key + " : "+ player.Value);
- }
- counter++;
- }
- }
- private static bool PlayerExist(Dictionary<string, Dictionary<string, long>> rank, string wormName)
- {
- bool playerExist = false;
- foreach (var team in rank.Values)
- {
- playerExist = team.ContainsKey(wormName);
- if (playerExist == true)
- {
- return true;
- }
- }
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement