daily pastebin goal
29%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 51 in 1 day
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Rextester
  7. {
  8.     public class Program
  9.     {
  10.         public static void Main(string[] args)
  11.         {
  12.             Dictionary<string, List<string>> playerHands = new Dictionary<string, List<string>>();
  13.            
  14.             while(true)
  15.             {
  16.                 //get the console input
  17.                 string userInput = Console.ReadLine();
  18.                
  19.                 if(userInput.Contains("JOKER")) {
  20.                     break;
  21.                 }
  22.                 //get the username
  23.                 string username = userInput.Split(':')[0];
  24.                 //create a list with the cards of the player
  25.                 List<string> cardsList = userInput.Split(':')[1].Split(new string[] { ", " }, StringSplitOptions.None).ToList();
  26.                
  27.                 //break the program if JOKER is present
  28.                
  29.                  
  30.                 //if it is a new player
  31.                 if (!playerHands.ContainsKey(username))
  32.                 {
  33.                    playerHands.Add(username, cardsList);
  34.                 }
  35.                 //if the player exists already
  36.                 else
  37.                 {
  38.                    //go through the cards
  39.                    foreach (var card in cardsList)
  40.                    {
  41.                        //check each card if it is present already in the previously drawn cards
  42.                        if(!playerHands[username].Contains(card))
  43.                        {
  44.                            //add it to the list only if not present in order not to have duplicates
  45.                            playerHands[username].Add(card);
  46.                        }
  47.                    }          
  48.                 }
  49.             }          
  50.         }
  51.     }
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top