Advertisement
Guest User

Untitled

a guest
Nov 26th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security;
  5.  
  6. namespace Problem_1._Ranking
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. var dictOfContests = new Dictionary<string, string>();
  13.  
  14. var contestWithPoInts = new Dictionary<string, int>();
  15. var usersWithContests = new Dictionary<string, Dictionary<string, int>>();
  16. while (true)
  17. {
  18. string input = Console.ReadLine();
  19. if (input == "end of contests")
  20. {
  21. break;
  22. }
  23.  
  24. string[] tokens = input
  25. .Split(":")
  26. .ToArray();
  27. string contest = tokens[0];
  28. string passwordForTheContest = tokens[1];
  29.  
  30. if (!dictOfContests.ContainsKey(contest))
  31. {
  32. dictOfContests[contest] = "";
  33. }
  34.  
  35. dictOfContests[contest] = passwordForTheContest;
  36. }
  37.  
  38. while (true)
  39. {
  40. string input = Console.ReadLine();
  41. if (input == "end of submissions")
  42. {
  43. break;
  44. }
  45. string[] tokens = input
  46. .Split("=>")
  47. .ToArray();
  48. string contest = tokens[0];
  49. string password = tokens[1];
  50. string username = tokens[2];
  51. int points = int.Parse(tokens[3]);
  52.  
  53. if (!dictOfContests.ContainsKey(contest))
  54. {
  55. continue;
  56. }
  57. else if (!(dictOfContests[contest] == password))
  58. {
  59. continue;
  60. }
  61. else
  62. {
  63. if (!(usersWithContests.ContainsKey(username)))
  64. {
  65. contestWithPoInts[contest] = points;
  66. usersWithContests[username] = new Dictionary<string, int>();
  67. usersWithContests[username].Add(contest, contestWithPoInts[contest]);
  68. }
  69. else if (!usersWithContests[username].ContainsKey(contest))
  70. {
  71. contestWithPoInts[contest] = points;
  72. usersWithContests[username].Add(contest, contestWithPoInts[contest]);
  73. }
  74. else
  75. {
  76. if (contestWithPoInts[contest] < points)
  77. {
  78. contestWithPoInts[contest] = points;
  79. usersWithContests[username] = contestWithPoInts;
  80. }
  81. }
  82. }
  83. }
  84.  
  85. var maxContest = new Dictionary<string, int>();
  86. foreach (var kvp in usersWithContests)
  87. {
  88. foreach (var Kvp in kvp.Value)
  89. {
  90. if (!maxContest.ContainsKey(kvp.Key))
  91. {
  92. maxContest[kvp.Key] = 0;
  93. }
  94. maxContest[kvp.Key] += Kvp.Value;
  95. }
  96. }
  97. int maxNum = maxContest.Values.Max();
  98. maxContest = maxContest.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x=> x.Value);
  99. string maxName = maxContest.First().Key;
  100. Console.WriteLine($"Best candidate is {maxName} with total {maxNum} points.");
  101. Console.WriteLine("Ranking: ");
  102. foreach (var kvp in usersWithContests.OrderBy(x => x.Key))
  103. {
  104. Console.WriteLine(kvp.Key);
  105. foreach (var Kvp in kvp.Value.OrderByDescending(x => x.Value))
  106. {
  107. Console.WriteLine($"# {Kvp.Key} -> {Kvp.Value}");
  108. }
  109. }
  110. }
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement