bullit3189

International SoftUniada-Dictionaries

Apr 9th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5. using System.Text;
  6.  
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. Dictionary<string,int> countryPoints = new Dictionary<string,int>();
  12. Dictionary<string,Dictionary<string,int>> countryPlayerPoints = new Dictionary<string,Dictionary<string,int>>();
  13.  
  14. while (true)
  15. {
  16. string command = Console.ReadLine();
  17.  
  18. if (command == "END")
  19. {
  20. break;
  21. }
  22.  
  23. string[] tokens = command.Split(" -> ");
  24. string country = tokens[0];
  25. string player = tokens[1];
  26. int points = int.Parse(tokens[2]);
  27.  
  28. if (!countryPoints.ContainsKey(country))
  29. {
  30. countryPoints.Add(country,points);
  31. }
  32. else
  33. {
  34. countryPoints[country]+=points;
  35. }
  36. if (!countryPlayerPoints.ContainsKey(country))
  37. {
  38. countryPlayerPoints.Add(country, new Dictionary<string,int>());
  39. countryPlayerPoints[country].Add(player,points);
  40. }
  41. else if (countryPlayerPoints.ContainsKey(country)== true && countryPlayerPoints[country].ContainsKey(player)==false)
  42. {
  43. countryPlayerPoints[country].Add(player,points);
  44. }
  45. else if (countryPlayerPoints.ContainsKey(country)== true && countryPlayerPoints[country].ContainsKey(player)==true)
  46. {
  47. countryPlayerPoints[country][player]+=points;
  48. }
  49. }
  50.  
  51. foreach (var kvp in countryPoints.OrderByDescending(x=>x.Value))
  52. {
  53. string country = kvp.Key;
  54. int points = kvp.Value;
  55.  
  56. Console.WriteLine("{0}: {1}",country,points);
  57.  
  58. foreach (var kvp1 in countryPlayerPoints)
  59. {
  60. string countryName = kvp1.Key;
  61.  
  62. if (countryName == country)
  63. {
  64. foreach (var inner in kvp1.Value)
  65. {
  66. string name = inner.Key;
  67. int playerPoints = inner.Value;
  68.  
  69. Console.WriteLine("-- {0} -> {1}",name,playerPoints);
  70. }
  71. }
  72. }
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment