Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text.RegularExpressions;
- namespace _05_Hands_of_Cards
- {
- public class HandsOfCards
- {
- public static void Main()
- {
- var cardsPowers = GetCardsPowers();
- var cardsTypes = GetCardsTypes();
- var players = new Dictionary<string, HashSet<int>>();
- string command = Console.ReadLine();
- while (command != "JOKER")
- {
- var tokens = command.Split(':');
- var playerName = tokens[0];
- var playerCards = tokens[1].Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
- foreach (var card in playerCards)
- {
- var cardPower = card.Substring(0, card.Length - 1);
- var cardType = card.Substring(card.Length - 1);
- int sum = cardsPowers[cardPower] * cardsTypes[cardType];
- if (!players.ContainsKey(playerName))
- {
- players[playerName] = new HashSet<int>();
- }
- players[playerName].Add(sum);
- }
- command = Console.ReadLine();
- }
- foreach (var player in players)
- {
- Console.WriteLine($"{player.Key}: {player.Value.Sum()}");
- }
- }
- //Card types(multiplier)
- static Dictionary<string, int> GetCardsTypes()
- {
- var cardsTypes = new Dictionary<string, int>();
- cardsTypes["S"] = 4;
- cardsTypes["H"] = 3;
- cardsTypes["D"] = 2;
- cardsTypes["C"] = 1;
- return cardsTypes;
- }
- //Card powers
- static Dictionary<string, int> GetCardsPowers()
- {
- var powers = new Dictionary<string, int>();
- for (int i = 2; i <= 10; i++)
- {
- powers[i.ToString()] = i;
- }
- powers["J"] = 11;
- powers["Q"] = 12;
- powers["K"] = 13;
- powers["A"] = 14;
- return powers;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement