Advertisement
Rayk

Untitled

Nov 4th, 2017
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace _05_Hands_of_Cards
  8. {
  9. public class HandsOfCards
  10. {
  11. public static void Main()
  12. {
  13. var cardsPowers = GetCardsPowers();
  14. var cardsTypes = GetCardsTypes();
  15.  
  16. var players = new Dictionary<string, HashSet<int>>();
  17.  
  18. string command = Console.ReadLine();
  19.  
  20. while (command != "JOKER")
  21. {
  22. var tokens = command.Split(':');
  23. var playerName = tokens[0];
  24. var playerCards = tokens[1].Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  25.  
  26. foreach (var card in playerCards)
  27. {
  28. var cardPower = card.Substring(0, card.Length - 1);
  29. var cardType = card.Substring(card.Length - 1);
  30.  
  31. int sum = cardsPowers[cardPower] * cardsTypes[cardType];
  32.  
  33. if (!players.ContainsKey(playerName))
  34. {
  35. players[playerName] = new HashSet<int>();
  36. }
  37. players[playerName].Add(sum);
  38. }
  39.  
  40. command = Console.ReadLine();
  41. }
  42.  
  43. foreach (var player in players)
  44. {
  45. Console.WriteLine($"{player.Key}: {player.Value.Sum()}");
  46. }
  47. }
  48. //Card types(multiplier)
  49. static Dictionary<string, int> GetCardsTypes()
  50. {
  51. var cardsTypes = new Dictionary<string, int>();
  52. cardsTypes["S"] = 4;
  53. cardsTypes["H"] = 3;
  54. cardsTypes["D"] = 2;
  55. cardsTypes["C"] = 1;
  56. return cardsTypes;
  57. }
  58.  
  59. //Card powers
  60. static Dictionary<string, int> GetCardsPowers()
  61. {
  62. var powers = new Dictionary<string, int>();
  63.  
  64. for (int i = 2; i <= 10; i++)
  65. {
  66. powers[i.ToString()] = i;
  67. }
  68. powers["J"] = 11;
  69. powers["Q"] = 12;
  70. powers["K"] = 13;
  71. powers["A"] = 14;
  72.  
  73. return powers;
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement