Advertisement
bullit3189

Judge - Dictionaries

Jan 24th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5.  
  6. public class Program
  7. {
  8. public static void Main()
  9. {
  10. Dictionary <string, Dictionary<string,int>> contestUserPoints = new Dictionary<string, Dictionary<string,int>>();
  11.  
  12. while (true)
  13. {
  14. string input = Console.ReadLine();
  15.  
  16. if (input == "no more time")
  17. {
  18. break;
  19. }
  20.  
  21. string[] tokens = input.Split(new [] {' ','-','>'},StringSplitOptions.RemoveEmptyEntries);
  22. string name = tokens[0];
  23. string contest = tokens[1];
  24. int points = int.Parse(tokens[2]);
  25.  
  26. if (!contestUserPoints.ContainsKey(contest))
  27. {
  28. contestUserPoints.Add(contest, new Dictionary<string,int>());
  29. contestUserPoints[contest].Add(name,points);
  30. }
  31. else if (contestUserPoints.ContainsKey(contest)==true && contestUserPoints[contest].ContainsKey(name)==false)
  32. {
  33. contestUserPoints[contest].Add(name,points);
  34. }
  35. else if (contestUserPoints.ContainsKey(contest)==true && contestUserPoints[contest].ContainsKey(name)==true)
  36. {
  37. if (points>contestUserPoints[contest][name])
  38. {
  39. contestUserPoints[contest][name] = points;
  40. }
  41. }
  42. }
  43.  
  44. foreach (var kvp in contestUserPoints)
  45. {
  46. string contest = kvp.Key;
  47. int participants = kvp.Value.Keys.Count();
  48.  
  49. Console.WriteLine("{0}: {1} participants",contest,participants);
  50. int position=1;
  51.  
  52. foreach (var currName in kvp.Value.OrderByDescending(x=>x.Value).ThenBy(x=>x.Key))
  53. {
  54.  
  55. string name = currName.Key;
  56. int points = currName.Value;
  57.  
  58. Console.WriteLine("{0}. {1} <::> {2}",position,name,points);
  59. position++;
  60. }
  61. }
  62.  
  63. Console.WriteLine("Individual standings:");
  64.  
  65. Dictionary<string,int> userPoints = new Dictionary<string,int>();
  66.  
  67. foreach (var kvp in contestUserPoints)
  68. {
  69. foreach (var user in kvp.Value)
  70. {
  71. if (!userPoints.ContainsKey(user.Key))
  72. {
  73. userPoints.Add(user.Key,user.Value);
  74. }
  75. else
  76. {
  77. userPoints[user.Key]+=user.Value;
  78. }
  79. }
  80.  
  81. }
  82.  
  83. int standing =1;
  84. foreach (var Kvp in userPoints.OrderByDescending(x=>x.Value).ThenBy(x=>x.Key))
  85. {
  86. string user = Kvp.Key;
  87. int points = Kvp.Value;
  88.  
  89. Console.WriteLine("{0}. {1} -> {2}",standing,user,points);
  90. standing++;
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement