Advertisement
Guest User

Untitled

a guest
Jun 18th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Program
  6. {
  7. static void Main()
  8. {
  9. Dictionary<string, Dictionary<string, int>> contestUserPoints = new
  10. Dictionary<string, Dictionary<string, int>>();
  11. Dictionary<string, int> individualStandings = new Dictionary<string, int>();
  12.  
  13. string input;
  14. while ((input = Console.ReadLine()) != "no more time")
  15. {
  16. string[] inputArgs = input.Split(" -> ", StringSplitOptions.RemoveEmptyEntries);
  17. string username = inputArgs[0];
  18. string contest = inputArgs[1];
  19. int points = int.Parse(inputArgs[2]);
  20.  
  21. if (!contestUserPoints.ContainsKey(contest))
  22. {
  23. contestUserPoints[contest] = new Dictionary<string, int>();
  24. }
  25. if (!contestUserPoints[contest].ContainsKey(username))
  26. {
  27. contestUserPoints[contest][username] = 0;
  28. }
  29. if (points > contestUserPoints[contest][username])
  30. {
  31. contestUserPoints[contest][username] = points;
  32. }
  33.  
  34. if (!individualStandings.ContainsKey(username))
  35. {
  36. individualStandings[username] = 0;
  37. }
  38. individualStandings[username] += points;
  39.  
  40. }
  41. foreach (var kvp in contestUserPoints)
  42. {
  43. Console.WriteLine($"{kvp.Key}: {kvp.Value.Count} participants");
  44. int counter = 0;
  45. var filteredDict = kvp.Value
  46. .OrderByDescending(x => x.Value)
  47. .ThenBy(x => x.Key)
  48. .ToDictionary(x => x.Key, x => x.Value);
  49. foreach (var pair in filteredDict)
  50. {
  51. counter++;
  52. Console.WriteLine($"{counter}. {pair.Key} <::> {pair.Value}");
  53. }
  54. }
  55. var orderIndividualStanding = individualStandings
  56. .OrderByDescending(x => x.Value)
  57. .ThenBy(x => x.Key)
  58. .ToDictionary(x => x.Key, x => x.Value);
  59. Console.WriteLine("Individual standings:");
  60. int counterSecond = 0;
  61. foreach (var kvp in orderIndividualStanding)
  62. {
  63. counterSecond++;
  64. Console.WriteLine($"{counterSecond}. {kvp.Key} -> {kvp.Value}");
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement