Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- public class Program
- {
- public static void Main()
- {
- Dictionary <string, Dictionary<string,int>> userContestPoints = new Dictionary<string, Dictionary<string,int>>();
- Dictionary <string,string> contestPass = new Dictionary<string,string>();
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "end of contests")
- {
- break;
- }
- string[] tokens = command.Split(':');
- string contest = tokens[0];
- string pass = tokens[1];
- if (!contestPass.ContainsKey(contest))
- {
- contestPass.Add(contest,pass);
- }
- }
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "end of submissions")
- {
- break;
- }
- string[] tokens = command.Split("=>");
- string contest = tokens[0];
- string pass = tokens[1];
- string username = tokens[2];
- int points = int.Parse(tokens[3]);
- if (contestPass.ContainsKey(contest))
- {
- if (contestPass[contest]==pass)
- {
- if (!userContestPoints.ContainsKey(username))
- {
- userContestPoints.Add(username,new Dictionary<string,int>());
- userContestPoints[username].Add(contest,points);
- }
- else if (userContestPoints.ContainsKey(username)==true && userContestPoints[username].ContainsKey(contest)==false)
- {
- userContestPoints[username].Add(contest,points);
- }
- else if (userContestPoints.ContainsKey(username)==true && userContestPoints[username].ContainsKey(contest)==true)
- {
- if (points> userContestPoints[username][contest])
- {
- userContestPoints[username][contest] =points;
- }
- }
- }
- }
- }
- string bestUser = string.Empty;
- int bestPoints =0;
- int pointsTotal=0;
- foreach (var kvp in userContestPoints)
- {
- string name = kvp.Key;
- foreach (var inner in kvp.Value)
- {
- pointsTotal += inner.Value;
- }
- if (pointsTotal>bestPoints)
- {
- bestPoints = pointsTotal;
- bestUser = name;
- }
- pointsTotal=0;
- }
- Console.WriteLine("Best candidate is {0} with total {1} points.",bestUser,bestPoints);
- Console.WriteLine("Ranking:");
- foreach (var currKvp in userContestPoints.OrderBy(x=>x.Key))
- {
- Console.WriteLine(currKvp.Key);
- foreach (var innerKvp in currKvp.Value.OrderByDescending(x=>x.Value))
- {
- Console.WriteLine("# {0} -> {1}",innerKvp.Key,innerKvp.Value);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement