Advertisement
Sim0o0na

Untitled

Jun 15th, 2017
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class _08_01_HandsOfCards
  6. {
  7.     static void Main()
  8.     {
  9.         string input = Console.ReadLine();
  10.         Dictionary<string, Dictionary<int, HashSet<int>>> houseOfCards = new Dictionary<string, Dictionary<int, HashSet<int>>>();
  11.         while (input != "JOKER")
  12.         {
  13.             string[] handInfo = input.Split(new char[] { ':', ',' }, StringSplitOptions.RemoveEmptyEntries);
  14.             string name = handInfo[0];
  15.             if (!houseOfCards.ContainsKey(name))
  16.             {
  17.                 houseOfCards.Add(name, new Dictionary<int, HashSet<int>>());
  18.                 for (int i = 1; i < 4; i++)
  19.                 {
  20.                     houseOfCards[name].Add(i, new HashSet<int>());
  21.                 }
  22.                 for (int i = 0; i < handInfo.Length; i++)
  23.                 {
  24.                     string currentCard = handInfo[i].Trim();
  25.                     int face = 0; int suite = 0;
  26.                     if (currentCard.Length > 2)
  27.                     {
  28.                         face = GetFace(currentCard.Substring(0, 2)); suite = GetSuite(currentCard.Substring(2));
  29.                     }
  30.                     else
  31.                     {
  32.                         face = GetFace(currentCard[0].ToString()); suite = GetSuite(currentCard[1].ToString());
  33.                     }
  34.                     if (!houseOfCards[name][suite].Contains(face))
  35.                     {
  36.                         houseOfCards[name][suite].Add(face);
  37.                     }
  38.                     input = Console.ReadLine();
  39.                 }
  40.                 foreach (var outerPair in houseOfCards)
  41.                 {
  42.                     int sum = 0;
  43.                     foreach (var innerPair in outerPair.Value)
  44.                     {
  45.                         sum += innerPair.Key * innerPair.Value.Sum();
  46.                     }
  47.                     Console.WriteLine($"{outerPair.Key}: {sum}");
  48.                 }
  49.             }
  50.         }
  51.     }
  52.     private static int GetSuite(string suite)
  53.     {
  54.         switch (suite)
  55.         {
  56.             case "S": return 4; break;
  57.             case "H": return 3; break;
  58.             case "D": return 2; break;
  59.             case "C": return 1; break;
  60.             default: return 0;
  61.         }
  62.     }
  63.     private static int GetFace(string face)
  64.     {
  65.         switch (face)
  66.         {
  67.             case "J": return 11; break;
  68.             case "Q": return 12; break;
  69.             case "K": return 13; break;
  70.             case "A": return 14; break;
  71.             default: return int.Parse(face);
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement