Advertisement
social1986

Untitled

Oct 18th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _05.Hands_of_Cards
  6. {
  7. public class Program
  8. {
  9. public static void Main()
  10. {
  11. var input = Console.ReadLine().Split(new char[] { ' ', ',', ':' }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList();
  12. var playerAndHisPoints = new Dictionary<string, List<string>>();
  13.  
  14. while (input[0] != "JOKER")
  15. {
  16. var playersCards = new List<string>();
  17.  
  18. for (int i = 1; i < input.Count; i++)
  19. {
  20. playersCards.Add(input[i]);
  21. }
  22.  
  23. if (playerAndHisPoints.ContainsKey(input[0]))
  24. {
  25. playerAndHisPoints[input[0]].AddRange(playersCards);
  26. }
  27. else
  28. {
  29. playerAndHisPoints[input[0]] = playersCards;
  30. }
  31. input = Console.ReadLine().Split(new char[] { ' ', ',', ':' }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList();
  32. }
  33.  
  34. foreach (var player in playerAndHisPoints.Keys)
  35. {
  36. var currentPLayerCards = playerAndHisPoints[player];
  37. var uniqueCurrentPLayerCards = currentPLayerCards.Distinct().ToList();
  38. var sum = 0;
  39.  
  40. for (int i = 0; i < uniqueCurrentPLayerCards.Count; i++)
  41. {
  42. sum += ReturnSumOfCards(uniqueCurrentPLayerCards[i]);
  43. }
  44. Console.WriteLine($"{player}: {sum}");
  45. }
  46. }
  47.  
  48. public static char TypeOfCards(string card)
  49. {
  50. var points = card.ToCharArray();
  51. return points[points.Length - 1];
  52. }
  53.  
  54. public static int ValueOfType(string type)
  55. {
  56. switch (TypeOfCards(type))
  57. {
  58. case 'S': return 4;
  59. case 'H': return 3;
  60. case 'D': return 2;
  61. case 'C': return 1;
  62. }
  63. return 1;
  64. }
  65.  
  66. public static int ValueOfCard(string card)
  67. {
  68. var cards = card;
  69. var number = cards.ToCharArray();
  70. string value = string.Empty;
  71.  
  72. for (int i = 0; i < card.Length - 1; i++)
  73. {
  74. value += card[i];
  75. }
  76. if (value == "J")
  77. {
  78. return 11;
  79. }
  80. else if (value == "Q")
  81. {
  82. return 12;
  83. }
  84. else if (value == "K")
  85. {
  86. return 13;
  87. }
  88. else if (value == "A")
  89. {
  90. return 14;
  91. }
  92. else
  93. {
  94. return int.Parse(value);
  95. }
  96. }
  97.  
  98. public static int ReturnSumOfCards(string card)
  99. {
  100. var sum = ValueOfType(card) * ValueOfCard(card);
  101. return sum;
  102. }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement