Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _05.Hands_of_Cards
- {
- public class Program
- {
- public static void Main()
- {
- var input = Console.ReadLine().Split(new char[] { ' ', ',', ':' }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList();
- var playerAndHisPoints = new Dictionary<string, List<string>>();
- while (input[0] != "JOKER")
- {
- var playersCards = new List<string>();
- for (int i = 1; i < input.Count; i++)
- {
- playersCards.Add(input[i]);
- }
- if (playerAndHisPoints.ContainsKey(input[0]))
- {
- playerAndHisPoints[input[0]].AddRange(playersCards);
- }
- else
- {
- playerAndHisPoints[input[0]] = playersCards;
- }
- input = Console.ReadLine().Split(new char[] { ' ', ',', ':' }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList();
- }
- foreach (var player in playerAndHisPoints.Keys)
- {
- var currentPLayerCards = playerAndHisPoints[player];
- var uniqueCurrentPLayerCards = currentPLayerCards.Distinct().ToList();
- var sum = 0;
- for (int i = 0; i < uniqueCurrentPLayerCards.Count; i++)
- {
- sum += ReturnSumOfCards(uniqueCurrentPLayerCards[i]);
- }
- Console.WriteLine($"{player}: {sum}");
- }
- }
- public static char TypeOfCards(string card)
- {
- var points = card.ToCharArray();
- return points[points.Length - 1];
- }
- public static int ValueOfType(string type)
- {
- switch (TypeOfCards(type))
- {
- case 'S': return 4;
- case 'H': return 3;
- case 'D': return 2;
- case 'C': return 1;
- }
- return 1;
- }
- public static int ValueOfCard(string card)
- {
- var cards = card;
- var number = cards.ToCharArray();
- string value = string.Empty;
- for (int i = 0; i < card.Length - 1; i++)
- {
- value += card[i];
- }
- if (value == "J")
- {
- return 11;
- }
- else if (value == "Q")
- {
- return 12;
- }
- else if (value == "K")
- {
- return 13;
- }
- else if (value == "A")
- {
- return 14;
- }
- else
- {
- return int.Parse(value);
- }
- }
- public static int ReturnSumOfCards(string card)
- {
- var sum = ValueOfType(card) * ValueOfCard(card);
- return sum;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement