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 _04.WormsWorldParty
- {
- class WormsWorldParty
- {
- static void Main()
- {
- Dictionary<string, Dictionary<string, long>> teams = new Dictionary<string, Dictionary<string, long>>();
- string input = Console.ReadLine();
- while (input != "quit")
- {
- string[] tokens = input.Split(new string[] { " -> " }, StringSplitOptions.None).Select(x => x.Trim()).ToArray();
- string playerName = tokens[0];
- string teamName = tokens[1];
- long score = long.Parse(tokens[2]);
- bool containsPlayer = false;
- foreach (var item in teams)
- {
- if (item.Value.ContainsKey(playerName))
- {
- containsPlayer = true;
- }
- }
- if (!containsPlayer)
- {
- if (!teams.ContainsKey(teamName))
- {
- teams.Add(teamName, new Dictionary<string, long>());
- }
- teams[teamName][playerName] = score;
- }
- input = Console.ReadLine();
- }
- teams =
- teams
- .OrderByDescending(t => t.Value.Values.Sum())
- .ThenByDescending(t => t.Value.Values.Average())
- .ToDictionary(k => k.Key, v => v.Value);
- int cntr = 1;
- foreach (var teamData in teams)
- {
- string teamName = teamData.Key;
- Dictionary<string, long> players = teamData.Value;
- players =
- players
- .OrderByDescending(s => s.Value)
- .ToDictionary(k => k.Key, v => v.Value);
- Console.WriteLine($"{cntr}. Team: {teamName} - {players.Values.Sum()}");
- foreach (var playerData in players)
- {
- string player = playerData.Key;
- long score = playerData.Value;
- Console.WriteLine($"###{player} : {score}");
- }
- cntr++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment