Advertisement
social1986

Untitled

Nov 27th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 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(':').Distinct().ToList();
  12. var playerAndHisCards = new Dictionary<string, HashSet<string>>();
  13.  
  14. while (input[0] != "JOKER")
  15. {
  16. var playersCards = input[1].Trim().Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
  17.  
  18. var player = input[0];
  19.  
  20. foreach (var card in playersCards)
  21. {
  22. playerAndHisCards[player].Add(card);
  23. }
  24.  
  25. input = Console.ReadLine().Split(':').Distinct().ToList();
  26. }
  27.  
  28. foreach (var player in playerAndHisCards.Keys)
  29. {
  30. var uniqueCurrentPlayerCards = playerAndHisCards[player];
  31. var sum = 0;
  32.  
  33. foreach (var card in uniqueCurrentPlayerCards)
  34. {
  35. sum += ReturnSumOfCards(card);
  36. }
  37. Console.WriteLine($"{player}: {sum}");
  38. }
  39. }
  40.  
  41. public static char TypeOfCards(string card)
  42. {
  43. var points = card.ToCharArray();
  44. return points[points.Length - 1];
  45. }
  46.  
  47. public static int ValueOfType(string type)
  48. {
  49. switch (TypeOfCards(type))
  50. {
  51. case 'S': return 4;
  52. case 'H': return 3;
  53. case 'D': return 2;
  54. case 'C': return 1;
  55. }
  56. return 1;
  57. }
  58.  
  59. public static int ValueOfCard(string card)
  60. {
  61. var cards = card;
  62. var number = cards.ToCharArray();
  63. string value = string.Empty;
  64.  
  65. for (int i = 0; i < card.Length - 1; i++)
  66. {
  67. value += card[i];
  68. }
  69. switch (value)
  70. {
  71. case "J": return 11;
  72. case "Q": return 12;
  73. case "K": return 13;
  74. case "A": return 14;
  75. default: return int.Parse(value);
  76. }
  77. }
  78.  
  79. public static int ReturnSumOfCards(string card)
  80. {
  81. var sum = ValueOfType(card) * ValueOfCard(card);
  82. return sum;
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement