LardaX

Hands-of-Cards

Oct 8th, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Hands_of_Cards
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<string, List<string>> playerCards = new Dictionary<string, List<string>>();
  14.             char[] splitters = { ':', ',', ' ' };
  15.  
  16.             string[] playerInformation = Console.ReadLine().Split(':').Distinct().ToArray();
  17.  
  18.             while (!playerInformation[0].Equals("JOKER"))
  19.             {
  20.                 if (!playerCards.ContainsKey(playerInformation[0]))
  21.                 {
  22.                     playerCards.Add(playerInformation[0], new List<string>());
  23.                 }
  24.  
  25.                 string[] cards = playerInformation[1].Split(splitters, StringSplitOptions.RemoveEmptyEntries).ToArray();
  26.  
  27.                 for (int i = 0; i < cards.Length; i++)
  28.                 {
  29.                     if (!playerCards[playerInformation[0]].Contains(cards[i]))
  30.                     {
  31.                         playerCards[playerInformation[0]].Add(cards[i]);
  32.                     }
  33.                 }
  34.  
  35.                 playerInformation = Console.ReadLine().Split(':').Distinct().ToArray();
  36.             }
  37.  
  38.             Dictionary<string, int> playerScore = new Dictionary<string, int>();
  39.  
  40.             foreach (KeyValuePair<string, List<string>> cardsInfo in playerCards)
  41.             {
  42.                 if (!playerScore.ContainsKey(cardsInfo.Key))
  43.                 {
  44.                     playerScore.Add(cardsInfo.Key, 0);
  45.                 }
  46.  
  47.                 for (int i = 0; i < cardsInfo.Value.Count; i++)
  48.                 {
  49.                     int power = GetPowerValue(cardsInfo.Value[i][0]);
  50.                     int multiplier = 1;
  51.                     if (cardsInfo.Value[i][0] == '1')
  52.                     {
  53.                         multiplier = GetTypeMultiplier(cardsInfo.Value[i][2]);
  54.                     }
  55.                     else
  56.                     {
  57.                         multiplier = GetTypeMultiplier(cardsInfo.Value[i][1]);
  58.                     }
  59.                     int totalScore = power * multiplier;
  60.                     playerScore[cardsInfo.Key] += totalScore;
  61.                 }
  62.             }
  63.  
  64.             foreach (KeyValuePair<string, int> playerInfo in playerScore)
  65.             {
  66.                 Console.WriteLine($"{playerInfo.Key}: {playerInfo.Value}");
  67.             }
  68.         }
  69.  
  70.         static int GetPowerValue(char power)
  71.         {
  72.             int value = 0;
  73.             switch (power)
  74.             {
  75.                 case '2': value = 2; break;
  76.                 case '3': value = 3; break;
  77.                 case '4': value = 4; break;
  78.                 case '5': value = 5; break;
  79.                 case '6': value = 6; break;
  80.                 case '7': value = 7; break;
  81.                 case '8': value = 8; break;
  82.                 case '9': value = 9; break;
  83.                 case '1': value = 10; break;
  84.                 case 'J': value = 11; break;
  85.                 case 'Q': value = 12; break;
  86.                 case 'K': value = 13; break;
  87.                 case 'A': value = 14; break;
  88.             }
  89.  
  90.             return value;
  91.         }
  92.  
  93.         static int GetTypeMultiplier(char type)
  94.         {
  95.             int multiplier = 0;
  96.             switch (type)
  97.             {
  98.                 case 'S': multiplier = 4; break;
  99.                 case 'H': multiplier = 3; break;
  100.                 case 'D': multiplier = 2; break;
  101.                 case 'C': multiplier = 1; break;
  102.             }
  103.  
  104.             return multiplier;
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment