Advertisement
pifka

Ranking

May 22nd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace ConsoleApp2
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var contestAndPasswords = new Dictionary<string, string>();
  14. var students = new SortedDictionary<string, Dictionary<string, int>>();
  15. var studentsAndPoints = new Dictionary<string, int>();
  16.  
  17. while (true)
  18. {
  19. var input = Console.ReadLine();
  20. if (input == "end of contests")
  21. {
  22. break;
  23. }
  24. else if (input.Contains(':'))
  25. {
  26. var contestAndPass = input.Split(':');
  27. var contest = contestAndPass[0];
  28. var password = contestAndPass[1];
  29.  
  30. if (!contestAndPasswords.ContainsKey(contest))
  31. {
  32. contestAndPasswords.Add(contest, password);
  33. }
  34. }
  35. }
  36. while (true)
  37. {
  38. var line = Console.ReadLine();
  39.  
  40. if (line == "end of submissions")
  41. {
  42. break;
  43. }
  44. else
  45. {
  46. var data = line.Split("=>");
  47.  
  48. var contest = data[0];
  49. var password = data[1];
  50. var name = data[2];
  51. var points = int.Parse(data[3]);
  52.  
  53. if (contestAndPasswords.ContainsKey(contest) && contestAndPasswords[contest] == password)
  54. {
  55. if (!students.ContainsKey(name))
  56. {
  57. students.Add(name, new Dictionary<string, int>());
  58. students[name].Add(contest, points);
  59. }
  60. else
  61. {
  62. if (!students[name].ContainsKey(contest))
  63. {
  64. students[name].Add(contest, points);
  65. }
  66. if (students[name][contest] < points)
  67. {
  68. students[name][contest] = points;
  69. }
  70. }
  71. }
  72. }
  73. }
  74. foreach (var student in students)
  75. {
  76. studentsAndPoints.Add(student.Key, 0);
  77. studentsAndPoints[student.Key] = student.Value.Values.Sum();
  78. }
  79.  
  80. foreach (var item in studentsAndPoints.OrderByDescending(x => x.Value))
  81. {
  82. var maxPoints = studentsAndPoints.Values.Max();
  83. if (item.Value == maxPoints)
  84. {
  85. Console.WriteLine($"Best candidate is {item.Key} with total {item.Value} points.");
  86. }
  87. }
  88.  
  89. Console.WriteLine("Ranking: ");
  90.  
  91. foreach (var item in students)
  92. {
  93. Console.WriteLine($"{item.Key}");
  94. foreach (var contest in students[item.Key].OrderByDescending(x => x.Value))
  95. {
  96. Console.WriteLine($"# {contest.Key} -> {contest.Value}");
  97. }
  98. }
  99. }
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement