Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace Problem_8._Ranking
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, string> contestInfo = new Dictionary<string, string>();
- var userInfo = new Dictionary<string, Dictionary<string, double>>();
- while (true)
- {
- var input = Console.ReadLine().Split(":", StringSplitOptions.RemoveEmptyEntries).ToArray();
- var end = input[0];
- if (end == "end of contests")
- {
- break;
- }
- var contests = input[0];
- var password = input[1];
- if (!contestInfo.ContainsKey(contests))
- {
- contestInfo.Add(contests, password);
- }
- }
- while (true)
- {
- var input = Console.ReadLine().Split("=>", StringSplitOptions.RemoveEmptyEntries).ToArray();
- var end = input[0];
- if (end == "end of submissions")
- {
- break;
- }
- var contest = input[0];
- var password = input[1];
- var username = input[2];
- var point = double.Parse(input[3]);
- if (contestInfo.ContainsKey(contest) && contestInfo[contest].Contains(password))
- {
- if (!userInfo.ContainsKey(username))
- {
- userInfo[username] = new Dictionary<string, double>();
- if (!userInfo[username].ContainsKey(contest))
- {
- userInfo[username].Add(contest, point);
- }
- else
- {
- double points = userInfo[username][contest];
- if (points < point)
- {
- userInfo[username][contest] = points;
- }
- }
- }
- else
- {
- if (!userInfo[username].ContainsKey(contest))
- {
- userInfo[username].Add(contest, point);
- }
- else
- {
- double points = userInfo[username][contest];
- if (points < point)
- {
- userInfo[username][contest] = points;
- }
- }
- }
- }
- }
- double bestSum = 0;
- var user = string.Empty;
- foreach (var sum in userInfo)
- {
- var currentSum = sum.Value.Sum(x => x.Value);
- var currentUser = sum.Key;
- if (currentSum > bestSum)
- {
- bestSum = currentSum;
- user = currentUser;
- }
- }
- Console.WriteLine($"Best candidate is {user} with total {bestSum} points.");
- userInfo = userInfo.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value.OrderByDescending(y => y.Value).ToDictionary(y => y.Key, y => y.Value));
- Console.WriteLine("Ranking:");
- foreach (var items in userInfo)
- {
- var username = items.Key;
- Console.WriteLine(username);
- foreach (var item in items.Value)
- {
- Console.WriteLine($"# {item.Key} -> {item.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement