Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Ranking
- {
- class Program
- {
- static void Main(string[] args)
- {
- var contests = new Dictionary<string, string>();
- var users = new Dictionary<string, Dictionary<string, int>>();
- string firstInput = string.Empty;
- while ((firstInput = Console.ReadLine()) != "end of contests")
- {
- string[] firstCommand = firstInput.Split(":");
- string password = firstCommand[1];
- string contestName = firstCommand[0];
- if (!contests.ContainsKey(password))
- {
- contests[password] = contestName;
- }
- }
- string secondInput = string.Empty;
- while ((secondInput = Console.ReadLine()) != "end of submissions")
- {
- string[] secondCommand = secondInput.Split("=>");
- string contest = secondCommand[0];
- string password = secondCommand[1];
- string user = secondCommand[2];
- int point = int.Parse(secondCommand[3]);
- if (contests.ContainsKey(password) && contests[password] == contest)
- {
- if (!users.ContainsKey(user))
- {
- users[user] = new Dictionary<string, int>();
- users[user][contest] = point;
- }
- if (users[user].ContainsKey(contest))
- {
- if (users[user][contest] < point)
- {
- users[user][contest] = point;
- }
- }
- else
- {
- users[user][contest] = point;
- }
- }
- else
- {
- continue;
- }
- }
- var userPointsSum = new Dictionary<string, int>();
- foreach (var item in users)
- {
- userPointsSum[item.Key] = item.Value.Values.Sum();
- }
- string bestName = userPointsSum.Keys.Max();
- int bestPoints = userPointsSum.Values.Max();
- foreach (var item in userPointsSum)
- {
- if (item.Value == bestPoints)
- {
- Console.WriteLine($"Best candidate is {item.Key} with total {item.Value} points.");
- }
- }
- Console.WriteLine("Ranking: ");
- foreach (var item in users.OrderBy(x => x.Key))
- {
- Console.WriteLine(item.Key);
- foreach (var kvp in item.Value.OrderByDescending(x=>x.Value))
- {
- Console.WriteLine($"# {kvp.Key} -> {kvp.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement