Guest User

Untitled

a guest
Nov 17th, 2020
28
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Ranking
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string firstInput = Console.ReadLine();
  12. Dictionary<string, string> contestCollection = new Dictionary<string, string>();
  13. Dictionary<string, Dictionary<string, int>> submissions = new Dictionary<string, Dictionary<string, int>>();
  14. Dictionary<string, int> totalPointsCollection = new Dictionary<string, int>();
  15. while (firstInput != "end of contests")
  16. {
  17. string[] arguments = firstInput.Split(':');
  18. string contestName = arguments[0];
  19. string password = arguments[1];
  20. contestCollection.Add(contestName, password);
  21. firstInput = Console.ReadLine();
  22. }
  23. string secondInput = Console.ReadLine();
  24. while (secondInput != "end of submissions")
  25. {
  26. string[] argumentsOfSubmission = secondInput.Split("=>");
  27. string contest = argumentsOfSubmission[0];
  28. string password = argumentsOfSubmission[1];
  29. string user = argumentsOfSubmission[2];
  30. int points = int.Parse(argumentsOfSubmission[3]);
  31. if (contestCollection.ContainsKey(contest) && contestCollection.ContainsValue(password))
  32. {
  33. if (submissions.ContainsKey(user))
  34. {
  35.  
  36. if (submissions[user].ContainsKey(contest))
  37. {
  38. if (submissions[user][contest] <= points)
  39. {
  40. submissions[user][contest] = points;
  41. }
  42. }
  43. else
  44. {
  45. submissions[user].Add(contest, points);
  46. totalPointsCollection[user] +=points;
  47. }
  48. }
  49. else
  50. {
  51. submissions.Add(user, new Dictionary<string, int>());
  52. totalPointsCollection.Add(user, points);
  53. submissions[user].Add(contest, points);
  54. }
  55.  
  56. }
  57. secondInput = Console.ReadLine();
  58. }
  59.  
  60. Console.WriteLine($"Best candidate is {totalPointsCollection.OrderByDescending(x => x.Value).First().Key} with total {totalPointsCollection.Values.Max()} points.");
  61. Console.WriteLine("Ranking:");
  62. foreach (var name in submissions.OrderBy(x=>x.Key))
  63. {
  64. Console.WriteLine(name.Key);
  65. foreach (var contestAndPoints in name.Value.OrderByDescending(x=>x.Value))
  66. {
  67. Console.WriteLine($"# {contestAndPoints.Key} -> {contestAndPoints.Value}");
  68. }
  69. }
  70. }
  71. }
  72. }
  73.  
RAW Paste Data