Advertisement
Guest User

Untitled

a guest
Oct 16th, 2017
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _05.Hands_of_Cards
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             char[] delimiters = new char[] { ',', ':', ' ' };
  12.             string[] input = Console.ReadLine().Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
  13.             Dictionary<string, List<string>> players = new Dictionary<string, List<string>>();
  14.  
  15.             string[] powers = new string[] { "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" };
  16.             string[] types = new string[] { "C", "D", "H", "S" };
  17.  
  18.             while (input[0] != "JOKER")
  19.             {
  20.                 List<string> cards = new List<string>();
  21.                 for (int i = 1; i < input.Length; i++)
  22.                 {
  23.                     cards.Add(input[i]);
  24.                 }
  25.  
  26.                 if (!players.ContainsKey(input[0]))
  27.                 {
  28.                     players.Add(input[0], cards);
  29.                 }
  30.                 else
  31.                 {
  32.                     players[input[0]].AddRange(cards);
  33.                 }
  34.                 input = Console.ReadLine().Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
  35.             }
  36.             foreach (var list in players)
  37.             {
  38.                 int currPoints = 0;
  39.                 List<string> currentList = list.Value.Distinct().ToList();
  40.                 foreach (var item in currentList)
  41.                 {
  42.                     if (Array.IndexOf(powers, item.Remove(item.Length - 1)) != -1 && Array.IndexOf(types, item[item.Length-1].ToString()) != -1)
  43.                     {
  44.                         currPoints += (Array.IndexOf(powers, item.Remove(item.Length - 1)) + 2) * (Array.IndexOf(types, item[item.Length - 1].ToString()) + 1);
  45.                     }
  46.                 }
  47.                 Console.WriteLine($"{list.Key}: {currPoints}");
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement