Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace MoreExercises_1_Ranking
- {
- class Program
- {
- static void Main()
- {
- //ranking according to POINTS from interview tasks
- // and from POINTS from exams in SoftUni
- Dictionary<string, string> contestPass = new Dictionary<string, string>();
- while (true)
- {
- string contest = Console.ReadLine();
- string[] array = new string[2];
- if (contest == "end of contests")
- {
- break;
- }
- array = contest.Split(':').ToArray();
- string contestName = array[0];
- string password = array[1];
- if (contestPass.ContainsKey(contestName) == false)
- {
- contestPass[contestName] = password;
- }
- }
- var namePoints = new Dictionary<string, int>();
- var userContestPoints = new Dictionary<string, Dictionary<string, int>>();
- while (true)
- {
- string input = Console.ReadLine();
- string[] arraySubmissions = new string[4];
- if (input == "end of submissions")
- {
- break;
- }
- arraySubmissions = Regex.Split(input, "=>").ToArray();
- string contestName = arraySubmissions[0];
- string password = arraySubmissions[1];
- string username = arraySubmissions[2];
- string points = arraySubmissions[3];
- if (contestPass.ContainsKey(contestName) == true && contestPass.ContainsValue(password) == true)
- {
- if (!userContestPoints.ContainsKey(username))
- {
- namePoints[username] = int.Parse(arraySubmissions[3]);
- userContestPoints[username] = new Dictionary<string, int>();
- var userContestResults = userContestPoints[username];
- userContestResults[contestName] = int.Parse(arraySubmissions[3]);
- }
- else
- {
- namePoints[username] += int.Parse(arraySubmissions[3]);
- var userContestResults = userContestPoints[username];
- userContestResults[contestName] = int.Parse(arraySubmissions[3]);
- }
- }
- //else
- //{
- //// if (userContestPoints.Values.Where(d=>d.ContainsValue(key)))
- //// {
- //// var query = test.Values // select inner dictionaries
- ////.Where(d => d.ContainsKey(key))
- //// }
- //}
- //var repeatedExam = userContestPoints
- // .ToDictionary(x => x.Key, x => x.ToDictionary(y => y.Key, y => y.Value)).Select(y=>y.Key );
- }
- var bestUser = namePoints.OrderByDescending(x => x.Value).First().Key;
- var maxValue = namePoints.Max(x => x.Value);
- Console.WriteLine($"Best candidate is {bestUser} with total {maxValue} points.");
- Console.WriteLine("Ranking:");
- foreach (var kvp in userContestPoints.OrderBy(x => x.Key))
- {
- string user = kvp.Key;
- Dictionary<string, int> userContestResults = kvp.Value;
- Console.WriteLine(user);
- foreach (var kvpValue in userContestResults.OrderByDescending(x => x.Value))
- {
- string contest = kvpValue.Key;
- int points = kvpValue.Value;
- Console.WriteLine($"# {contest} -> {points}");
- }
- //userContestPoints.OrderBy(a => a.Key).SelectMany(a => a.Value.Select(b => "# " + b.Key + " -> " + b.Value))
- //.ToList()
- //.ForEach(Console.WriteLine);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement