Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace P01Ranking
- {
- class Program
- {
- static void Main(string[] args)
- {
- var contestAndPassword = new Dictionary<string, string>();
- var result = new Dictionary<string, Dictionary<string, double>>();
- while (true)
- {
- string end = Console.ReadLine();
- if (end == "end of contests")
- {
- break;
- }
- List<string> command = end.Split(":").ToList();
- string contest = command[0];
- string password = command[1];
- if (!contestAndPassword.ContainsKey(contest))
- {
- contestAndPassword[contest] = password;
- }
- }
- while (true)
- {
- string end = Console.ReadLine();
- if (end == "end of submissions")
- {
- break;
- }
- List<string> command = end.Split("=>").ToList();
- string contest = command[0];
- string password = command[1];
- string username = command[2];
- double points = double.Parse(command[3]);
- if (contestAndPassword.ContainsKey(contest) && contestAndPassword.ContainsValue(password))
- {
- if (!result.ContainsKey(username))
- {
- result[username] = new Dictionary<string, double>();
- result[username][contest] = points;
- }
- else if (result[username].ContainsKey(contest))
- {
- if (result[username][contest] < points)
- {
- result[username][contest] = points;
- }
- }
- else
- {
- result[username][contest] = points;
- }
- }
- }
- double max = 0;
- string name = "";
- foreach (var item in result)
- {
- double currentMax = item.Value.Values.Sum();
- if (currentMax > max)
- {
- max = currentMax;
- name = item.Key;
- }
- }
- Console.WriteLine($"Best candidate is {name} with total {max} points.");
- Console.WriteLine("Ranking: ");
- foreach (var item in result.OrderBy(x => x.Key))
- {
- Console.WriteLine(item.Key);
- foreach (var item1 in item.Value.OrderByDescending(x => x.Value))
- {
- Console.WriteLine($"# {item1.Key} -> {item1.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement