Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _08.Ranking
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var record = new Dictionary<string, string>();
  12. var candidates = new Dictionary<string, Dictionary<string, int>>();
  13.  
  14. string command = Console.ReadLine();
  15. while (command != "end of contests")
  16. {
  17. string[] tokens = command
  18. .Split(':', StringSplitOptions.RemoveEmptyEntries)
  19. .ToArray();
  20. string contest = tokens[0];
  21. string password = tokens[1];
  22.  
  23. record.Add(contest, password);
  24.  
  25. command = Console.ReadLine();
  26. }
  27. string input = Console.ReadLine();
  28.  
  29. while (input != "end of submissions")
  30. {
  31. string[] info = input.Split("=>", StringSplitOptions.RemoveEmptyEntries).ToArray(); ;
  32. string contest = info[0];
  33. string password = info[1];
  34. string user = info[2];
  35. int points = int.Parse(info[3]);
  36.  
  37. foreach (var competition in record)
  38. {
  39. if (record.ContainsKey(contest) && record[contest] == password)
  40. {
  41. if (!candidates.ContainsKey(user))
  42. {
  43. candidates.Add(user, new Dictionary<string, int>());
  44. candidates[user].Add(contest, points);
  45. }
  46. else
  47. {
  48. if (!candidates[user].ContainsKey(contest))
  49. {
  50. candidates[user].Add(contest, points);
  51. }
  52. else
  53. {
  54. int currentPoints = candidates[user][contest];
  55. if (points > currentPoints)
  56. {
  57. candidates[user][contest] = points;
  58. }
  59. }
  60. }
  61.  
  62. }
  63. }
  64. input = Console.ReadLine();
  65. }
  66.  
  67. int totalPoints = int.MinValue;
  68. var bestName = string.Empty;
  69. foreach (var participant in candidates)
  70. {
  71. int currentPoints = participant.Value.Values.Sum();
  72.  
  73. if (currentPoints > totalPoints)
  74. {
  75. totalPoints = currentPoints;
  76. bestName = participant.Key;
  77. }
  78. }
  79.  
  80. Console.WriteLine($"Best candidate is {bestName} with total" +
  81. $" {totalPoints} points.");
  82.  
  83. Console.WriteLine("Ranking:");
  84. foreach (var name in candidates.OrderBy(x => x.Key))
  85. {
  86. Console.WriteLine($"{name.Key}");
  87.  
  88. foreach (var module in name.Value.OrderByDescending(x => x.Value))
  89. {
  90. Console.WriteLine($"# {module.Key} -> {module.Value}");
  91. }
  92. }
  93. }
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement