Advertisement
Guest User

Untitled

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