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)
- {
- Dictionary<string, string> map1 =
- new Dictionary<string, string>();
- Dictionary<string, Dictionary<string,int>> map2 =
- new Dictionary<string, Dictionary<string, int>>();
- int totalPoints = 0;
- while (true)
- {
- string input = Console.ReadLine();
- if (input=="end of contests")
- {
- break;
- }
- string[] array = input.Split(":");
- string contest = array[0];
- string passwordForContest = array[1];
- if (!map1.ContainsKey(contest))
- {
- map1.Add(contest, passwordForContest);
- }
- }
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "end of submissions")
- {
- break;
- }
- string[] array = input.Split("=>");
- string contest = array[0];
- string password = array[1];
- string username = array[2];
- int points = int.Parse(array[3]);
- if (map1.ContainsKey(contest) && map1.ContainsValue(password))
- {
- if (!map2.ContainsKey(username))
- {
- map2.Add(username, new Dictionary<string, int>());
- if (!map2[username].ContainsKey(contest))
- {
- map2[username].Add(contest, points);
- }
- else
- {
- if (points > map2[username][contest])
- {
- map2[username][contest] = points;
- }
- }
- }
- else
- {
- if (!map2[username].ContainsKey(contest))
- {
- map2[username].Add(contest, points);
- }
- else
- {
- if (points > map2[username][contest])
- {
- map2[username][contest] = points;
- }
- }
- }
- }
- }
- foreach (var person in map2)
- {
- foreach (var pointScore in person.Value)
- {
- totalPoints += pointScore.Value;
- }
- Console.WriteLine($"Best candidate is {person.Key} with total {person.Value.Values.Sum()} points.");
- break;
- }
- Console.WriteLine("Ranking: ");
- foreach (var user in map2.OrderBy(u=>u.Key))
- {
- Console.WriteLine(user.Key);
- foreach (var item in user.Value.OrderByDescending(p=>p.Value))
- {
- Console.WriteLine($"# {item.Key} -> {item.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement