Advertisement
Guest User

Untitled

a guest
Oct 1st, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _05.Hands_of_Cards
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var houseOfCards = new Dictionary<string, Dictionary<int, HashSet<int>>>();
  14. string input = Console.ReadLine();
  15. while (input != "JOKER")
  16. {
  17. var handInfo = input.Split(new char[] { ':', ',' }, StringSplitOptions.RemoveEmptyEntries);
  18. var name = handInfo[0];
  19. if (!houseOfCards.ContainsKey(name))
  20. {
  21. houseOfCards.Add(name, new Dictionary<int, HashSet<int>>());
  22. for (int i = 1; i <= 4; i++)
  23. {
  24. houseOfCards[name].Add(i, new HashSet<int>());
  25. }
  26. }
  27. for (int i = 1; i < handInfo.Length; i++)
  28. {
  29. var currentCard = handInfo[i].Trim();
  30. var face = 0;
  31. var suite = 0;
  32. if (currentCard.Length > 2)
  33. {
  34. face = GetFace(currentCard.Substring(0, 2));
  35. suite = GetSuite(currentCard.Substring(2));
  36. }
  37. else
  38. {
  39. face = GetFace(currentCard[0].ToString());
  40. suite = GetSuite(currentCard[1].ToString());
  41. }
  42.  
  43. if (!houseOfCards[name][suite].Contains(face))
  44. {
  45. houseOfCards[name][suite].Add(face);
  46. }
  47. }
  48.  
  49. input = Console.ReadLine();
  50. }
  51.  
  52. foreach (var outerPair in houseOfCards)
  53. {
  54. var sum = 0;
  55. foreach (var inner in outerPair.Value)
  56. {
  57. sum += inner.Key * inner.Value.Sum();
  58. }
  59. Console.WriteLine("{0}: {1}", outerPair.Key, sum);
  60. }
  61. }
  62. static int GetSuite(string suite)
  63. {
  64. switch (suite)
  65. {
  66. case "S":
  67. return 4;
  68. case "H":
  69. return 3;
  70. case "D":
  71. return 2;
  72. case "C":
  73. return 1;
  74. default:
  75. return 0;
  76. }
  77. }
  78.  
  79. static int GetFace(string face)
  80. {
  81. switch (face)
  82. {
  83.  
  84. case "J":
  85. return 11;
  86. case "Q":
  87. return 12;
  88. case "K":
  89. return 13;
  90. case "A":
  91. return 14;
  92.  
  93. default:
  94. return int.Parse(face);
  95. }
  96. }
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement