Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- You are given a sequence of people and for every person what cards he draws from the deck.
- The input will be separate lines in the format: {personName}: {PT, PT, PT,… PT}
- Where P (2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A) is the power of the card and T (S, H, D, C) is the type.
- The input ends when a "JOKER" is drawn. The name can contain any ASCII symbol except ':'.
- The input will always be valid and in the format described, there is no need to check it.
- A single person cannot have more than one card with the same power and type, if he draws such a card he discards it.
- The people are playing with multiple decks. Each card has a value that is calculated by the power multiplied by the type.
- Powers 2 to 10 have the same value and J to A are 11 to 14.
- Types are mapped to multipliers the following way (S -> 4, H-> 3, D -> 2, C -> 1).
- Finally print out the total value each player has in his hand in the format: {personName}: {value}
- */
- namespace Hands_of_Cards
- {
- using System;
- using System.Collections.Generic;
- internal static class HandsOfCards
- {
- private static void Main()
- {
- var cardsPower = new Dictionary<string, int>
- {
- { "j", 11 },
- { "q", 12 },
- { "k", 13 },
- { "a", 14 }
- };
- var cardsType = new Dictionary<char, int>
- {
- { 'c', 1 },
- { 'd', 2 },
- { 'h', 3 },
- { 's', 4 }
- };
- var playersPoints = new Dictionary<string, int>();
- var playersCards = new Dictionary<string, HashSet<string>>();
- while (true)
- {
- var playerHandParts = Console.ReadLine().Split(
- new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
- if (playerHandParts[0].Trim() == "JOKER")
- {
- break;
- }
- var playerName = playerHandParts[0].Trim();
- if (!playersCards.ContainsKey(playerName))
- {
- playersCards.Add(playerName, new HashSet<string>());
- }
- var handCards = playerHandParts[1].Split(
- new char[] { ',', ' ', ';', '.' }, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < handCards.Length; i++)
- {
- playersCards[playerName].Add(handCards[i].Trim().ToLower());
- }
- }
- foreach (var entry in playersCards)
- {
- if (!playersPoints.ContainsKey(entry.Key))
- {
- playersPoints[entry.Key] = 0;
- }
- foreach (var card in entry.Value)
- {
- var cardPower = card.Substring(0, card.Length - 1);
- var cardType = card[card.Length - 1];
- if (cardsPower.ContainsKey(cardPower))
- {
- playersPoints[entry.Key] +=
- cardsPower[cardPower] * cardsType[cardType];
- }
- else
- {
- playersPoints[entry.Key] +=
- int.Parse(cardPower) * cardsType[cardType];
- }
- }
- }
- foreach (var person in playersPoints)
- {
- Console.WriteLine("{0}: {1}", person.Key, person.Value);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement