Advertisement
Guest User

02 judge

a guest
Aug 9th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02._Judge___More_Exercise
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string command = "";
  12.  
  13. //var dictStuPoint = new Dictionary<string, List<int>>();
  14. //var dictContenst = new Dictionary<string, string>();
  15.  
  16. Dictionary<string, Dictionary<string, int>> contens = new Dictionary<string, Dictionary<string, int>>();
  17. var dictNameToTotalPoint = new Dictionary<string, int>();
  18.  
  19. while ((command = Console.ReadLine())!= "no more time")
  20. {
  21. string[] comandArr = command.Split("->",StringSplitOptions.RemoveEmptyEntries).ToArray();
  22. string userName = comandArr[0];
  23. string contenst = comandArr[1];
  24. int points = int.Parse(comandArr[2]);
  25. if (!contens.ContainsKey(contenst))
  26. {
  27. contens.Add(contenst, new Dictionary<string, int>());
  28. contens[contenst].Add(userName, points);
  29. if (dictNameToTotalPoint.ContainsKey(userName))
  30. {
  31. dictNameToTotalPoint[userName] += points;
  32. }
  33. else
  34. {
  35. dictNameToTotalPoint.Add(userName, points);
  36. }
  37.  
  38. }
  39. else
  40. {
  41. if (!contens[contenst].ContainsKey(userName))
  42. {
  43. contens[contenst].Add(userName, points);
  44. if (dictNameToTotalPoint.ContainsKey(userName))
  45. {
  46. dictNameToTotalPoint[userName] += points;
  47. }
  48. else
  49. {
  50. dictNameToTotalPoint.Add(userName, points);
  51. }
  52.  
  53.  
  54. }
  55. else
  56. {
  57. dictNameToTotalPoint[userName] += points;
  58. int maxVelue = int.MinValue;
  59. if (maxVelue<=points)
  60. {
  61. maxVelue = points;
  62. contens[contenst][userName] = maxVelue;
  63. dictNameToTotalPoint[userName] = maxVelue;
  64. }
  65.  
  66.  
  67. }
  68. }
  69.  
  70. }
  71.  
  72. foreach (var item in contens)
  73. {
  74. int countOne = 1;
  75. int numbersStu = item.Value.Count;
  76. Console.WriteLine($"{item.Key.Trim()}: {numbersStu} participants");
  77. foreach (var fistrsKVP in item.Value.OrderByDescending(x=> x.Value).ThenBy(x=>x.Key))
  78. {
  79.  
  80. Console.WriteLine($"{countOne}. {fistrsKVP.Key}<::> {fistrsKVP.Value}");
  81. countOne++;
  82. }
  83. }
  84. int count = 1;
  85. dictNameToTotalPoint = dictNameToTotalPoint.OrderByDescending(x => x.Value).ThenBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
  86. Console.WriteLine($"Individual standings:");
  87. foreach (var item in dictNameToTotalPoint)
  88. {
  89. string name = item.Key;
  90. int points = item.Value;
  91. Console.WriteLine($"{count}. {name}-> {points}");
  92. count++;
  93. }
  94.  
  95. }
  96. }
  97. }
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement