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 contestsListOfPasswords = new Dictionary<string, List<string>>();
- var usernamesListOfContests= new SortedDictionary<string, List<string>>();
- var usernamesListOfPoints= new Dictionary<string, List<int>>();
- string firstInput = string.Empty;
- while((firstInput=Console.ReadLine())!="end of contests")
- {
- string[] inputArray = firstInput.Split(':');
- string contest = inputArray[0];
- string password = inputArray[1];
- if (contestsListOfPasswords.ContainsKey(contest) == false)
- {
- contestsListOfPasswords[contest] = new List<string>();
- contestsListOfPasswords[contest].Add(password);
- }
- else if (contestsListOfPasswords.ContainsKey(contest) == true)
- {
- contestsListOfPasswords[contest].Add(password);
- }
- }
- string secondInput = string.Empty;
- while((secondInput=Console.ReadLine())!="end of submissions")
- {
- string[] secondInputArray = secondInput.Split("=>");
- string contest = secondInputArray[0];
- string password = secondInputArray[1];
- string username = secondInputArray[2];
- int points = int.Parse(secondInputArray[3]);
- if (contestsListOfPasswords.ContainsKey(contest))//validate the contest
- {
- if (contestsListOfPasswords[contest].Contains(password))//validate the password
- {
- if (usernamesListOfContests.ContainsKey(username)==false)
- {
- usernamesListOfContests[username] = new List<string>();
- usernamesListOfContests[username].Add(contest);
- usernamesListOfPoints[username] = new List<int>();
- usernamesListOfPoints[username].Add(points);
- }
- else if(usernamesListOfContests.ContainsKey(username)==true)
- {
- bool haveThaSameContest = false;
- foreach (var currentContest in usernamesListOfContests[username])
- {
- if (currentContest == contest)//If you receive the same contest check for update the points
- {
- haveThaSameContest = true;
- int indexOfCurrentContest=usernamesListOfContests[username].IndexOf(contest);
- if (points > usernamesListOfPoints[username][indexOfCurrentContest])
- {
- usernamesListOfPoints[username][indexOfCurrentContest] = points;
- break;
- }
- }
- }
- if (haveThaSameContest == false)
- {
- usernamesListOfContests[username].Add(contest);
- usernamesListOfPoints[username].Add(points);
- }
- }
- }
- }
- }
- int maxSum = 0;
- string bestCandidate = string.Empty;
- foreach (var kvp in usernamesListOfPoints)
- {
- string username = kvp.Key;
- var listOfPoints = kvp.Value;
- int currentSumOfPoints = listOfPoints.Sum();
- if (currentSumOfPoints > maxSum)
- {
- maxSum = currentSumOfPoints;
- bestCandidate = username;
- }
- }
- Console.WriteLine($"Best candidate is {bestCandidate} with total {maxSum} points.");
- Console.WriteLine("Ranking: ");
- foreach (var kvp in usernamesListOfContests)
- {
- string username = kvp.Key;
- Console.WriteLine($"{username}");
- var listOfContest = kvp.Value;
- var listOfPoints = usernamesListOfPoints[username];
- var temp = new Dictionary<string, int>();
- for (int i = 0; i < listOfContest.Count(); i++)
- {
- temp[listOfContest[i]] = listOfPoints[i];
- }
- foreach (var kvp1 in temp.OrderByDescending(x=>x.Value))
- {
- string contest = kvp1.Key;
- int points = kvp1.Value;
- Console.WriteLine($"# {contest} -> {points}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement