Advertisement
Guest User

Untitled

a guest
Feb 6th, 2017
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. class HandsOfCards
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         Dictionary<string, HashSet<string>> dictList = new Dictionary<string, HashSet<string>>();
  9.         HashSet<string> playerCards = new HashSet<string>();
  10.         string input = Console.ReadLine();
  11.         while (input != "JOKER")
  12.         {
  13.             string[] command = input.Split(':');
  14.             string name = command[0];
  15.             string cardsCommand = command[1];
  16.             string[] cards = cardsCommand.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
  17.             for (int i = 0; i < cards.Length; i++)
  18.             {
  19.                 string currentCard = cards[i];          
  20.                 currentCard = currentCard.Replace("0", "");
  21.                 if (!dictList.ContainsKey(name))
  22.                     dictList[name] = new HashSet<string>();
  23.                 playerCards.Add(currentCard);
  24.             }
  25.             foreach (var item in playerCards)
  26.                 dictList[name].Add(item);
  27.             playerCards.Clear();
  28.             input = Console.ReadLine();
  29.         }
  30.         foreach (var kvp in dictList)
  31.         {
  32.             long score = 0;
  33.             for (int i = 0; i < kvp.Value.Count; i++)
  34.             {
  35.                 score = 0;
  36.                 foreach (var item in kvp.Value)
  37.                 {
  38.                     char card = item[0];
  39.                     char type = item[1];
  40.                     score += CardValue(card, type);
  41.                 }
  42.             }
  43.             Console.WriteLine("{0}: {1}", kvp.Key, score);
  44.         }
  45.     }
  46.     public static int CardValue(char card, char type)
  47.     {
  48.         int cardValue = 0;
  49.         int typeValue = 0;
  50.         int result = 1;
  51.         switch (card)
  52.         {
  53.             case '2':
  54.                 cardValue = 2;
  55.                 break;
  56.             case '3':
  57.                 cardValue = 3;
  58.                 break;
  59.             case '4':
  60.                 cardValue = 4;
  61.                 break;
  62.             case '5':
  63.                 cardValue = 5;
  64.                 break;
  65.             case '6':
  66.                 cardValue = 6;
  67.                 break;
  68.             case '7':
  69.                 cardValue = 7;
  70.                 break;
  71.             case '8':
  72.                 cardValue = 8;
  73.                 break;
  74.             case '9':
  75.                 cardValue = 9;
  76.                 break;
  77.             case '1':
  78.                 cardValue = 10;
  79.                 break;
  80.             case 'J':
  81.                 cardValue = 11;
  82.                 break;
  83.             case 'Q':
  84.                 cardValue = 12;
  85.                 break;
  86.             case 'K':
  87.                 cardValue = 13;
  88.                 break;
  89.             case 'A':
  90.                 cardValue = 14;
  91.                 break;
  92.         }
  93.         switch (type)
  94.         {
  95.             case 'S':
  96.                 typeValue = 4;
  97.                 break;
  98.             case 'H':
  99.                 typeValue = 3;
  100.                 break;
  101.             case 'D':
  102.                 typeValue = 2;
  103.                 break;
  104.             case 'C':
  105.                 typeValue = 1;
  106.                 break;                
  107.         }
  108.         result = typeValue * cardValue;
  109.         return result;
  110.     }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement