Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text;
- using System.Collections;
- class Program
- {
- static void Main()
- {
- string command = Console.ReadLine();
- Dictionary<string, Dictionary<string, int>> users = new Dictionary<string, Dictionary<string, int>>();
- while(command != "Season end")
- {
- if (command.Contains("->"))
- {
- string[] line = command.Split(" -> ");
- string name = line[0];
- string position = line[1];
- int points = int.Parse(line[2]);
- if (!users.ContainsKey(name))
- {
- users.Add(name, new Dictionary<string, int>()
- {
- {position, points }
- });
- }
- else
- {
- if (users.ContainsKey(name))
- {
- if (!users[name].ContainsKey(position))
- {
- users[name].Add(position, points);
- }
- else
- {
- if(users[name][position] < points)
- {
- users[name][position] = points;
- }
- }
- }
- }
- }
- else
- {
- string[] line = command.Split(" vs ");
- string firstPlayer = line[0];
- string secondPlayer = line[1];
- if(users.ContainsKey(firstPlayer) && users.ContainsKey(secondPlayer))
- {
- foreach (var first in users[firstPlayer])
- {
- foreach (var second in users[secondPlayer])
- {
- if(first.Key == second.Key)
- {
- if(users[firstPlayer].Values.Sum() > users[secondPlayer].Values.Sum())
- {
- users.Remove(secondPlayer);
- }
- else
- {
- users.Remove(firstPlayer);
- }
- }
- }
- }
- }
- }
- command = Console.ReadLine();
- }
- foreach (var item in users.OrderByDescending(s => s.Value.Values.Sum()).ThenBy(x => x.Key))
- {
- int totalSkills = item.Value.Values.Sum();
- Console.WriteLine($"{item.Key}: {totalSkills} skill");
- foreach (var kvp in item.Value.OrderByDescending(s => s.Value))
- {
- Console.WriteLine($"- {kvp.Key} <::> {kvp.Value}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement