Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _08.Ranking
- {
- class Program
- {
- static void Main(string[] args)
- {
- var record = new Dictionary<string, string>();
- var candidates = new Dictionary<string, Dictionary<string, int>>();
- string command = Console.ReadLine();
- while (command != "end of contests")
- {
- string[] tokens = command
- .Split(':', StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- string contest = tokens[0];
- string password = tokens[1];
- record.Add(contest, password);
- command = Console.ReadLine();
- }
- string input = Console.ReadLine();
- while (input != "end of submissions")
- {
- string[] info = input.Split("=>", StringSplitOptions.RemoveEmptyEntries).ToArray(); ;
- string contest = info[0];
- string password = info[1];
- string user = info[2];
- int points = int.Parse(info[3]);
- foreach (var competition in record)
- {
- if (record.ContainsKey(contest) && record[contest] == password)
- {
- if (!candidates.ContainsKey(user))
- {
- candidates.Add(user, new Dictionary<string, int>());
- candidates[user].Add(contest, points);
- }
- else
- {
- if (!candidates[user].ContainsKey(contest))
- {
- candidates[user].Add(contest, points);
- }
- else
- {
- int currentPoints = candidates[user][contest];
- if (points > currentPoints)
- {
- candidates[user][contest] = points;
- }
- }
- }
- }
- }
- input = Console.ReadLine();
- }
- int totalPoints = int.MinValue;
- var bestName = string.Empty;
- foreach (var participant in candidates)
- {
- int currentPoints = participant.Value.Values.Sum();
- if (currentPoints > totalPoints)
- {
- totalPoints = currentPoints;
- bestName = participant.Key;
- }
- }
- Console.WriteLine($"Best candidate is {bestName} with total" +
- $" {totalPoints} points.");
- Console.WriteLine("Ranking:");
- foreach (var name in candidates.OrderBy(x => x.Key))
- {
- Console.WriteLine($"{name.Key}");
- foreach (var module in name.Value.OrderByDescending(x => x.Value))
- {
- Console.WriteLine($"# {module.Key} -> {module.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement