Advertisement
bullit3189

SoftUniExamResults aka Ranking-TFExam01Jul18

Jan 31st, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace _04SoftUniExamResults
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. Dictionary<string, int> userPoints = new Dictionary<string, int>();
  12. Dictionary<string, int> examSubs = new Dictionary<string, int>();
  13.  
  14. while (true)
  15. {
  16. string command = Console.ReadLine();
  17.  
  18. if (command == "exam finished")
  19. {
  20. break;
  21. }
  22.  
  23. if (!command.Contains("banned"))
  24. {
  25. string[] tokens = command.Split("-");
  26.  
  27. string username = tokens[0];
  28. string examName = tokens[1];
  29. int points = int.Parse(tokens[2]);
  30.  
  31. if (!userPoints.ContainsKey(username))
  32. {
  33. userPoints.Add(username, points);
  34. }
  35. else
  36. {
  37. if (points>userPoints[username])
  38. {
  39. userPoints[username] = points;
  40. }
  41. }
  42.  
  43. if (!examSubs.ContainsKey(examName))
  44. {
  45. examSubs.Add(examName, 1);
  46. }
  47. else
  48. {
  49. examSubs[examName] += 1;
  50. }
  51. }
  52. else
  53. {
  54. string[] tokens = command.Split("-");
  55.  
  56. string username = tokens[0];
  57.  
  58. if (userPoints.ContainsKey(username))
  59. {
  60. userPoints.Remove(username);
  61. }
  62. }
  63. }
  64.  
  65. Console.WriteLine("Results:");
  66.  
  67. foreach (var kvp in userPoints.OrderByDescending(x=>x.Value).ThenBy(x=>x.Key))
  68. {
  69. string username = kvp.Key;
  70. int points = kvp.Value;
  71.  
  72. Console.WriteLine($"{username} | {points}");
  73. }
  74.  
  75. Console.WriteLine("Submissions:");
  76.  
  77. foreach (var kvp in examSubs.OrderByDescending(x=>x.Value).ThenBy(x=>x.Key))
  78. {
  79. string language = kvp.Key;
  80. int submissionsCount = kvp.Value;
  81.  
  82. Console.WriteLine($"{language} - {submissionsCount}");
  83. }
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement