Advertisement
Guest User

Untitled

a guest
Apr 10th, 2017
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Collections.Generic;
  4.  
  5. namespace _01.Cards
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var pattern = @"([1]?[0-9AJKQ])([SHDC])";
  12.             //matches 1 between zero and one times, as many times as possible, giving back as needed, then continues matching the power
  13.             //and suit
  14.  
  15.             var input = Console.ReadLine();
  16.             var regex = new Regex(pattern);
  17.             var cards = new List<Match>();
  18.             var validCards = regex.Matches(input);
  19.  
  20.             foreach (Match match in validCards)
  21.             {
  22.                 var power = 0;
  23.  
  24.                 if (int.TryParse(match.Groups[1].Value, out power)) //see if the card is between 2-10
  25.                 {
  26.                     if (power < 2 || power > 10) //if the power is not valid, continue
  27.                     {
  28.                         continue;
  29.                     }
  30.                 }
  31.                 cards.Add(match); //add the matches(cards) to the list
  32.             }
  33.             Console.WriteLine(string.Join(", ", cards));
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement