Advertisement
zhivko1985

Hands_of_cards

Mar 9th, 2017
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 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 _5.Hands_of_cards
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var separators = new char []{ ' ', ',' };
  14. var dict = new Dictionary<string, string>();
  15. string input = Console.ReadLine();
  16. while (!input.Equals("JOKER"))
  17. {
  18. var nameAndCards = input.Split(':').ToArray();
  19. string name = nameAndCards[0];
  20. if (!dict.ContainsKey(name))
  21. {
  22. dict[name] = nameAndCards[1];
  23. }
  24. else
  25. {
  26. dict[name] += nameAndCards[1];
  27. }
  28. input = Console.ReadLine();
  29. }
  30. foreach (var item in dict)
  31. {
  32. var CardsList = item.Value.Split(separators, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList();
  33. int multipl = 1;
  34. int cardpower = 0;
  35. long sum=0;
  36. foreach (var word in CardsList)
  37. {
  38. if (string.Join("",word.Skip(word.Length-1))=="S")
  39. {
  40. multipl = 4;
  41. }
  42. else if (string.Join("",word.Skip(word.Length - 1)) == "H")
  43. {
  44. multipl = 3;
  45. }
  46. else if (string.Join("", word.Skip(word.Length - 1)) == "D")
  47. {
  48. multipl = 2;
  49. }
  50. //-----------------------------------------------------------
  51. if (string.Join("",word.Take(word.Length - 1)) == "2")
  52. {
  53. cardpower = 2;
  54. }
  55. else if (string.Join("", word.Take(word.Length - 1)) == "3")
  56. {
  57. cardpower = 3;
  58. }
  59. else if (string.Join("", word.Take(word.Length - 1)) == "4")
  60. {
  61. cardpower = 4;
  62. }
  63. else if (string.Join("", word.Take(word.Length - 1)) == "5")
  64. {
  65. cardpower = 5;
  66. }
  67. else if (string.Join("", word.Take(word.Length - 1)) == "6")
  68. {
  69. cardpower = 6;
  70. }
  71. else if (string.Join("", word.Take(word.Length - 1)) == "7")
  72. {
  73. cardpower = 7;
  74. }
  75. else if (string.Join("", word.Take(word.Length - 1)) == "8")
  76. {
  77. cardpower = 8;
  78. }
  79. else if (string.Join("", word.Take(word.Length - 1)) == "9")
  80. {
  81. cardpower = 9;
  82. }
  83. else if (string.Join("", word.Take(word.Length - 1)) == "10")
  84. {
  85. cardpower = 10;
  86. }
  87. else if (string.Join("", word.Take(word.Length - 1)) == "J")
  88. {
  89. cardpower = 11;
  90. }
  91. else if (string.Join("", word.Take(word.Length - 1)) == "Q")
  92. {
  93. cardpower = 12;
  94. }
  95. else if (string.Join("", word.Take(word.Length - 1)) == "K")
  96. {
  97. cardpower = 13;
  98. }
  99. else if (string.Join("", word.Take(word.Length - 1)) == "A")
  100. {
  101. cardpower = 14;
  102. }
  103. sum += cardpower * multipl;
  104. cardpower = 0;
  105. multipl = 1;
  106. }
  107. Console.WriteLine("{0}: {1}", item.Key, sum);
  108. sum = 0;
  109. }
  110. }
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement